2021-06-21 03:10:27 +00:00
|
|
|
import createFlash from '~/flash';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { __ } from '~/locale';
|
2020-07-08 12:09:33 +00:00
|
|
|
import { getBinary } from './services/image_service';
|
|
|
|
|
|
|
|
const imageRepository = () => {
|
|
|
|
const images = new Map();
|
2021-06-21 03:10:27 +00:00
|
|
|
const flash = (message) =>
|
|
|
|
createFlash({
|
|
|
|
message,
|
|
|
|
});
|
2020-07-08 12:09:33 +00:00
|
|
|
|
|
|
|
const add = (file, url) => {
|
|
|
|
getBinary(file)
|
2020-12-23 21:10:24 +00:00
|
|
|
.then((content) => images.set(url, content))
|
2020-07-08 12:09:33 +00:00
|
|
|
.catch(() => flash(__('Something went wrong while inserting your image. Please try again.')));
|
|
|
|
};
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const get = (path) => images.get(path);
|
2020-11-13 18:09:11 +00:00
|
|
|
|
2020-07-08 12:09:33 +00:00
|
|
|
const getAll = () => images;
|
|
|
|
|
2020-11-13 18:09:11 +00:00
|
|
|
return { add, get, getAll };
|
2020-07-08 12:09:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default imageRepository;
|