@lonik/oh-image 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.js +13 -8
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -10,7 +10,8 @@ function queryToOptions(processKey, uri) {
|
|
|
10
10
|
const [path, query] = uri.split("?");
|
|
11
11
|
if (!query || !path) return {
|
|
12
12
|
shouldProcess: false,
|
|
13
|
-
path: ""
|
|
13
|
+
path: "",
|
|
14
|
+
queryString: ""
|
|
14
15
|
};
|
|
15
16
|
const parsed = queryString.parse(query, {
|
|
16
17
|
parseBooleans: true,
|
|
@@ -33,19 +34,23 @@ function queryToOptions(processKey, uri) {
|
|
|
33
34
|
if (processKey in parsed) return {
|
|
34
35
|
shouldProcess: true,
|
|
35
36
|
options: parsed,
|
|
36
|
-
path
|
|
37
|
+
path,
|
|
38
|
+
queryString: query
|
|
37
39
|
};
|
|
38
40
|
else return {
|
|
39
41
|
shouldProcess: false,
|
|
40
|
-
path
|
|
42
|
+
path,
|
|
43
|
+
queryString: query
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
//#endregion
|
|
45
48
|
//#region src/plugin/file-utils.ts
|
|
46
|
-
async function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
async function getHash(value) {
|
|
50
|
+
return createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
51
|
+
}
|
|
52
|
+
async function getFileHash(filePath, queryString$1) {
|
|
53
|
+
return `${await getHash(await readFile(filePath))}-${await getHash(queryString$1)}`;
|
|
49
54
|
}
|
|
50
55
|
async function readFileSafe(path) {
|
|
51
56
|
try {
|
|
@@ -226,12 +231,12 @@ function ohImage(options) {
|
|
|
226
231
|
const fileId = basename(url);
|
|
227
232
|
const path = join(cacheDir, fileId);
|
|
228
233
|
const ext = extname(url).slice(1);
|
|
229
|
-
const image = await readFileSafe(path);
|
|
230
234
|
const imageEntry = imageEntries.get(url);
|
|
231
235
|
if (!imageEntry) {
|
|
232
236
|
console.warn("Image entry not found with id: " + url);
|
|
233
237
|
return next();
|
|
234
238
|
}
|
|
239
|
+
const image = await readFileSafe(path);
|
|
235
240
|
if (image) {
|
|
236
241
|
res.setHeader("Content-Type", `image/${ext}`);
|
|
237
242
|
res.end(image);
|
|
@@ -252,7 +257,7 @@ function ohImage(options) {
|
|
|
252
257
|
const origin = parsed.path;
|
|
253
258
|
const { name, ext } = parse(parsed.path);
|
|
254
259
|
const metadata = await sharp(parsed.path).metadata();
|
|
255
|
-
const hash = await getFileHash(origin);
|
|
260
|
+
const hash = await getFileHash(origin, parsed.queryString);
|
|
256
261
|
const mergedOptions = {
|
|
257
262
|
...config,
|
|
258
263
|
...parsed.options
|
package/package.json
CHANGED