@editframe/vite-plugin 0.18.27-beta.0 → 0.19.4-beta.0
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/index.js +49 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -2,8 +2,15 @@ import { forbidRelativePaths } from "./forbidRelativePaths.js";
|
|
|
2
2
|
import { sendTaskResult } from "./sendTaskResult.js";
|
|
3
3
|
import { rm } from "node:fs/promises";
|
|
4
4
|
import path, { join } from "node:path";
|
|
5
|
+
import { Client, createURLToken } from "@editframe/api";
|
|
5
6
|
import { cacheImage, findOrCreateCaptions, generateTrack, generateTrackFragmentIndex, md5FilePath } from "@editframe/assets";
|
|
6
7
|
import debug from "debug";
|
|
8
|
+
const getEditframeClient = () => {
|
|
9
|
+
const token = process.env.EF_TOKEN;
|
|
10
|
+
const efHost = process.env.EF_HOST;
|
|
11
|
+
if (!token) throw new Error("EF_TOKEN environment variable must be set");
|
|
12
|
+
return new Client(token, efHost);
|
|
13
|
+
};
|
|
7
14
|
const vitePluginEditframe = (options) => {
|
|
8
15
|
return {
|
|
9
16
|
name: "vite-plugin-editframe",
|
|
@@ -63,6 +70,48 @@ const vitePluginEditframe = (options) => {
|
|
|
63
70
|
log(`Serving image file ${absolutePath}`);
|
|
64
71
|
cacheImage(options.cacheRoot, absolutePath).then((taskResult) => sendTaskResult(req, res, taskResult)).catch(next);
|
|
65
72
|
break;
|
|
73
|
+
case "@ef-sign-url": {
|
|
74
|
+
if (req.method !== "POST") {
|
|
75
|
+
res.writeHead(405, { Allow: "POST" });
|
|
76
|
+
res.end();
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
log("Signing URL token");
|
|
80
|
+
let body = "";
|
|
81
|
+
req.on("data", (chunk) => {
|
|
82
|
+
body += chunk.toString();
|
|
83
|
+
});
|
|
84
|
+
req.on("end", async () => {
|
|
85
|
+
try {
|
|
86
|
+
const payload = JSON.parse(body);
|
|
87
|
+
log("Token signing request payload:", payload);
|
|
88
|
+
const { url, params } = payload;
|
|
89
|
+
if (!url) {
|
|
90
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
91
|
+
res.end(JSON.stringify({ error: "URL is required" }));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const client = getEditframeClient();
|
|
95
|
+
let fullUrl = url;
|
|
96
|
+
if (params) {
|
|
97
|
+
const urlObj = new URL(url);
|
|
98
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
99
|
+
urlObj.searchParams.set(key, String(value));
|
|
100
|
+
});
|
|
101
|
+
fullUrl = urlObj.toString();
|
|
102
|
+
}
|
|
103
|
+
log("Creating token for full URL:", fullUrl);
|
|
104
|
+
const token = await createURLToken(client, fullUrl);
|
|
105
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
106
|
+
res.end(JSON.stringify({ token }));
|
|
107
|
+
} catch (error) {
|
|
108
|
+
log(`Error signing URL token: ${error}`);
|
|
109
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
110
|
+
res.end(JSON.stringify({ error: "Failed to sign URL token" }));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
66
115
|
default:
|
|
67
116
|
log(`Unknown asset type ${efPrefix}`);
|
|
68
117
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.4-beta.0",
|
|
4
4
|
"description": "Editframe vite plugin",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "UNLICENSED",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@editframe/
|
|
22
|
+
"@editframe/api": "0.19.4-beta.0",
|
|
23
|
+
"@editframe/assets": "0.19.4-beta.0",
|
|
23
24
|
"connect": "^3.7.0",
|
|
24
25
|
"debug": "^4.3.5",
|
|
25
26
|
"mime": "^4.0.3",
|