const { HttpStatusError } = require('common-errors');
const { FILES_BACKGROUND_IMAGE_FIELD } = require('../constant.js');

module.exports = function isValidBackgroundOrigin(data) {
  const backgroundImage = data[FILES_BACKGROUND_IMAGE_FIELD];

  if (backgroundImage) {
    const { url } = backgroundImage;
    const provider = this.provider('update', data);
    const isValidOrigin = url.indexOf(provider.cname) === 0;

    if (!isValidOrigin) {
      throw new HttpStatusError(412, 'invalid origin');
    }
  }

  return data;
};

@@ -298,16 +298,248 @@
 ndImage;
+%0A%0A    /**%0A     *  Using 'upload' selector here since background images are always%0A     *  contained in the persistent store%0A     *  https://github.com/makeomatic/ms-files/blob/master/src/custom/cappasity-select-bucket.js#L10%0A     */
 %0A    con
@@ -573,12 +573,12 @@
 ('up
-date
+load
 ', d

correct a name of a selector of a provider getter (#44)