2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } 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-03-08 18:12:59 +05:30
|
|
|
const flash = (message) => new Flash(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;
|