@editframe/vite-plugin 0.7.0-beta.8 → 0.8.0-beta.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/package.json +6 -9
- package/dist/packages/vite-plugin/forbidRelativePaths.cjs +0 -8
- package/dist/packages/vite-plugin/index.cjs +0 -65
- package/dist/packages/vite-plugin/sendTaskResult.cjs +0 -56
- /package/dist/packages/vite-plugin/{packages/vite-plugin/src/forbidRelativePaths.d.ts → forbidRelativePaths.d.ts} +0 -0
- /package/dist/packages/vite-plugin/{packages/vite-plugin/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/packages/vite-plugin/{packages/vite-plugin/src/sendTaskResult.d.ts → sendTaskResult.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
4
4
|
"description": "Editframe vite plugin",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"import": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
},
|
|
11
|
-
"require": {
|
|
12
|
-
"default": "./dist/packages/vite-plugin/index.cjs",
|
|
13
|
-
"types": "./dist/packages/vite-plugin/index.d.ts"
|
|
8
|
+
"types": "./dist/packages/vite-plugin/index.d.ts",
|
|
9
|
+
"default": "./dist/packages/vite-plugin/index.js"
|
|
14
10
|
}
|
|
15
11
|
}
|
|
16
12
|
},
|
|
@@ -23,7 +19,7 @@
|
|
|
23
19
|
"author": "",
|
|
24
20
|
"license": "UNLICENSED",
|
|
25
21
|
"dependencies": {
|
|
26
|
-
"@editframe/assets": "0.
|
|
22
|
+
"@editframe/assets": "0.8.0-beta.1",
|
|
27
23
|
"debug": "^4.3.5",
|
|
28
24
|
"mime": "^4.0.3",
|
|
29
25
|
"node-html-parser": "^6.1.13",
|
|
@@ -31,8 +27,9 @@
|
|
|
31
27
|
},
|
|
32
28
|
"devDependencies": {
|
|
33
29
|
"@types/dom-webcodecs": "^0.1.11",
|
|
34
|
-
"@types/node": "^20.14.
|
|
30
|
+
"@types/node": "^20.14.13",
|
|
35
31
|
"connect": "^3.7.0",
|
|
32
|
+
"typescript": "^5.5.4",
|
|
36
33
|
"vite-plugin-dts": "^3.9.1",
|
|
37
34
|
"vite-tsconfig-paths": "^4.3.2"
|
|
38
35
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const forbidRelativePaths = (req) => {
|
|
4
|
-
if (req.url?.includes("..")) {
|
|
5
|
-
throw new Error("Relative paths are forbidden");
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
exports.forbidRelativePaths = forbidRelativePaths;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
const debug = require("debug");
|
|
5
|
-
const assets = require("@editframe/assets");
|
|
6
|
-
const forbidRelativePaths = require("./forbidRelativePaths.cjs");
|
|
7
|
-
const sendTaskResult = require("./sendTaskResult.cjs");
|
|
8
|
-
const vitePluginEditframe = (options) => {
|
|
9
|
-
return {
|
|
10
|
-
name: "vite-plugin-editframe",
|
|
11
|
-
configureServer(server) {
|
|
12
|
-
server.middlewares.use(async (req, res, next) => {
|
|
13
|
-
const log = debug("ef:vite-plugin");
|
|
14
|
-
if (req.url?.startsWith("/@ef")) {
|
|
15
|
-
forbidRelativePaths.forbidRelativePaths(req);
|
|
16
|
-
} else {
|
|
17
|
-
return next();
|
|
18
|
-
}
|
|
19
|
-
log(`Handling ${req.url}`);
|
|
20
|
-
const requestPath = req.url.replace(/^\/@ef-[^\/]+\//, "");
|
|
21
|
-
const assetPath = requestPath.replace(/\?.*$/, "");
|
|
22
|
-
const absolutePath = path.join(options.root, assetPath).replace("dist/", "src/");
|
|
23
|
-
options.cacheRoot = options.cacheRoot.replace("dist/", "src/");
|
|
24
|
-
const efPrefix = req.url.split("/")[1];
|
|
25
|
-
switch (efPrefix) {
|
|
26
|
-
case "@ef-asset": {
|
|
27
|
-
if (req.method !== "HEAD") {
|
|
28
|
-
res.writeHead(405, { Allow: "HEAD" });
|
|
29
|
-
res.end();
|
|
30
|
-
}
|
|
31
|
-
assets.md5FilePath(absolutePath).then((md5) => {
|
|
32
|
-
res.writeHead(200, {
|
|
33
|
-
etag: md5
|
|
34
|
-
});
|
|
35
|
-
res.end();
|
|
36
|
-
}).catch(next);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case "@ef-track-fragment-index": {
|
|
40
|
-
log(`Serving track fragment index for ${absolutePath}`);
|
|
41
|
-
assets.generateTrackFragmentIndex(options.cacheRoot, absolutePath).then((taskResult) => sendTaskResult.sendTaskResult(req, res, taskResult)).catch(next);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case "@ef-track": {
|
|
45
|
-
log(`Serving track for ${absolutePath}`);
|
|
46
|
-
assets.generateTrack(options.cacheRoot, absolutePath, req.url).then((taskResult) => sendTaskResult.sendTaskResult(req, res, taskResult)).catch(next);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
case "@ef-captions":
|
|
50
|
-
log(`Serving captions for ${absolutePath}`);
|
|
51
|
-
assets.findOrCreateCaptions(options.cacheRoot, absolutePath).then((taskResult) => sendTaskResult.sendTaskResult(req, res, taskResult)).catch(next);
|
|
52
|
-
break;
|
|
53
|
-
case "@ef-image":
|
|
54
|
-
log(`Serving image file ${absolutePath}`);
|
|
55
|
-
assets.cacheImage(options.cacheRoot, absolutePath).then((taskResult) => sendTaskResult.sendTaskResult(req, res, taskResult)).catch(next);
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
58
|
-
log(`Unknown asset type ${efPrefix}`);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.vitePluginEditframe = vitePluginEditframe;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const node_fs = require("node:fs");
|
|
4
|
-
const mime = require("mime");
|
|
5
|
-
const debug = require("debug");
|
|
6
|
-
const sendTaskResult = (req, res, taskResult) => {
|
|
7
|
-
const { cachePath, md5Sum } = taskResult;
|
|
8
|
-
const filePath = cachePath;
|
|
9
|
-
const headers = {
|
|
10
|
-
etag: md5Sum
|
|
11
|
-
};
|
|
12
|
-
const log = debug("ef:sendfile");
|
|
13
|
-
try {
|
|
14
|
-
log(`Sending file ${filePath}`);
|
|
15
|
-
const stats = node_fs.statSync(filePath);
|
|
16
|
-
if (req.headers.range) {
|
|
17
|
-
const [x, y] = req.headers.range.replace("bytes=", "").split("-");
|
|
18
|
-
let end = Number.parseInt(y ?? "0", 10) || stats.size - 1;
|
|
19
|
-
const start = Number.parseInt(x ?? "0", 10) || 0;
|
|
20
|
-
if (end >= stats.size) {
|
|
21
|
-
end = stats.size - 1;
|
|
22
|
-
}
|
|
23
|
-
if (start >= stats.size) {
|
|
24
|
-
log("Range start is greater than file size");
|
|
25
|
-
res.setHeader("Content-Range", `bytes */${stats.size}`);
|
|
26
|
-
res.statusCode = 416;
|
|
27
|
-
return res.end();
|
|
28
|
-
}
|
|
29
|
-
res.writeHead(206, {
|
|
30
|
-
...headers,
|
|
31
|
-
"Content-Type": mime.getType(filePath) || "text/plain",
|
|
32
|
-
"Cache-Control": "max-age=3600",
|
|
33
|
-
"Content-Range": `bytes ${start}-${end}/${stats.size}`,
|
|
34
|
-
"Content-Length": end - start + 1,
|
|
35
|
-
"Accept-Ranges": "bytes"
|
|
36
|
-
});
|
|
37
|
-
log(`Sending ${filePath} range ${start}-${end}/${stats.size}`);
|
|
38
|
-
const readStream = node_fs.createReadStream(filePath, { start, end });
|
|
39
|
-
readStream.pipe(res);
|
|
40
|
-
} else {
|
|
41
|
-
res.writeHead(200, {
|
|
42
|
-
...headers,
|
|
43
|
-
"Content-Type": mime.getType(filePath) || "text/plain",
|
|
44
|
-
"Cache-Control": "max-age=3600",
|
|
45
|
-
"Contetn-Length": stats.size
|
|
46
|
-
});
|
|
47
|
-
log(`Sending ${filePath}`);
|
|
48
|
-
const readStream = node_fs.createReadStream(filePath);
|
|
49
|
-
readStream.pipe(res);
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
log("Error sending file", error);
|
|
53
|
-
console.error(error);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.sendTaskResult = sendTaskResult;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|