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

26 lines
603 B
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import createFlash from '~/flash';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2020-07-28 23:09:34 +05:30
import { getBinary } from './services/image_service';
const imageRepository = () => {
const images = new Map();
2021-09-30 23:02:18 +05:30
const flash = (message) =>
createFlash({
message,
});
2020-07-28 23:09:34 +05:30
const add = (file, url) => {
getBinary(file)
2021-03-08 18:12:59 +05:30
.then((content) => images.set(url, content))
2020-07-28 23:09:34 +05:30
.catch(() => flash(__('Something went wrong while inserting your image. Please try again.')));
};
2021-03-08 18:12:59 +05:30
const get = (path) => images.get(path);
2021-01-29 00:20:46 +05:30
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;