debian-mirror-gitlab/app/assets/javascripts/static_site_editor/image_repository.js

23 lines
599 B
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { __ } from '~/locale';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as Flash } from '~/flash';
2020-07-28 23:09:34 +05:30
import { getBinary } from './services/image_service';
const imageRepository = () => {
const images = new Map();
const flash = message => new Flash(message);
const add = (file, url) => {
getBinary(file)
.then(content => images.set(url, content))
.catch(() => flash(__('Something went wrong while inserting your image. Please try again.')));
};
2021-01-29 00:20:46 +05:30
const get = path => images.get(path);
2020-07-28 23:09:34 +05:30
const getAll = () => images;
2021-01-29 00:20:46 +05:30
return { add, get, getAll };
2020-07-28 23:09:34 +05:30
};
export default imageRepository;