1 | "use strict";
|
2 |
|
3 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
4 |
|
5 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
6 |
|
7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8 |
|
9 |
|
10 |
|
11 | var CACHE = Symbol.for("com.cloudinary.cache");
|
12 | var CACHE_ADAPTER = Symbol.for("com.cloudinary.cacheAdapter");
|
13 |
|
14 | var _require = require('./utils'),
|
15 | ensurePresenceOf = _require.ensurePresenceOf,
|
16 | generate_transformation_string = _require.generate_transformation_string;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var CacheAdapter = function () {
|
24 | function CacheAdapter() {
|
25 | _classCallCheck(this, CacheAdapter);
|
26 | }
|
27 |
|
28 | _createClass(CacheAdapter, [{
|
29 | key: "get",
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | value: function get(publicId, type, resourceType, transformation, format) {}
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | }, {
|
53 | key: "set",
|
54 | value: function set(publicId, type, resourceType, transformation, format, value) {}
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 | }, {
|
61 | key: "flushAll",
|
62 | value: function flushAll() {}
|
63 | }]);
|
64 |
|
65 | return CacheAdapter;
|
66 | }();
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var Cache = {
|
74 | |
75 |
|
76 |
|
77 |
|
78 | CacheAdapter,
|
79 | |
80 |
|
81 |
|
82 |
|
83 | setAdapter(adapter) {
|
84 | if (this.adapter) {
|
85 | console.warn("Overriding existing cache adapter");
|
86 | }
|
87 | this.adapter = adapter;
|
88 | },
|
89 | |
90 |
|
91 |
|
92 |
|
93 | getAdapter() {
|
94 | return this.adapter;
|
95 | },
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | get(publicId, options) {
|
103 | if (!this.adapter) {
|
104 | return undefined;
|
105 | }
|
106 | ensurePresenceOf({ publicId });
|
107 | var transformation = generate_transformation_string(_extends({}, options));
|
108 | return this.adapter.get(publicId, options.type || 'upload', options.resource_type || 'image', transformation, options.format);
|
109 | },
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | set(publicId, options, value) {
|
118 | if (!this.adapter) {
|
119 | return undefined;
|
120 | }
|
121 | ensurePresenceOf({ publicId, value });
|
122 | var transformation = generate_transformation_string(_extends({}, options));
|
123 | return this.adapter.set(publicId, options.type || 'upload', options.resource_type || 'image', transformation, options.format, value);
|
124 | },
|
125 | |
126 |
|
127 |
|
128 |
|
129 | flushAll() {
|
130 | if (!this.adapter) {
|
131 | return undefined;
|
132 | }
|
133 | return this.adapter.flushAll();
|
134 | }
|
135 |
|
136 | };
|
137 |
|
138 |
|
139 | Object.defineProperty(Cache, "instance", {
|
140 | get() {
|
141 | return global[CACHE];
|
142 | }
|
143 | });
|
144 | Object.defineProperty(Cache, "adapter", {
|
145 | |
146 |
|
147 |
|
148 |
|
149 | get() {
|
150 | return global[CACHE_ADAPTER];
|
151 | },
|
152 | |
153 |
|
154 |
|
155 |
|
156 | set(adapter) {
|
157 | global[CACHE_ADAPTER] = adapter;
|
158 | }
|
159 | });
|
160 | Object.freeze(Cache);
|
161 |
|
162 |
|
163 | var symbols = Object.getOwnPropertySymbols(global);
|
164 | if (symbols.indexOf(CACHE) < 0) {
|
165 | global[CACHE] = Cache;
|
166 | }
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | module.exports = Cache; |
\ | No newline at end of file |