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