pinokiod 6.0.65 → 6.0.66
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 +1 -1
- package/server/lib/inject_router.js +6 -121
- package/server/views/app.ejs +0 -9
package/package.json
CHANGED
|
@@ -5,81 +5,6 @@ const path = require("path")
|
|
|
5
5
|
|
|
6
6
|
const { resolveDesktopEventWorkspace } = require("./desktop_event_router")
|
|
7
7
|
|
|
8
|
-
const escapeRegex = (value) => String(value || "").replace(/[|\\{}()[\]^$+?.]/g, "\\$&")
|
|
9
|
-
|
|
10
|
-
const wildcardToRegex = (pattern) => {
|
|
11
|
-
const source = escapeRegex(pattern).replace(/\*/g, ".*")
|
|
12
|
-
return new RegExp(`^${source}$`)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const normalizeInjectPatterns = (value) => {
|
|
16
|
-
const list = Array.isArray(value) ? value : [value]
|
|
17
|
-
const patterns = list
|
|
18
|
-
.map((item) => (typeof item === "string" ? item.trim() : ""))
|
|
19
|
-
.filter(Boolean)
|
|
20
|
-
return patterns.length ? patterns : ["*"]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const normalizeInjectEntries = (injectConfig) => {
|
|
24
|
-
if (!injectConfig) {
|
|
25
|
-
return []
|
|
26
|
-
}
|
|
27
|
-
const entries = Array.isArray(injectConfig) ? injectConfig : [injectConfig]
|
|
28
|
-
const normalized = []
|
|
29
|
-
for (const entry of entries) {
|
|
30
|
-
const config = typeof entry === "string" ? { href: entry } : entry
|
|
31
|
-
if (!config || typeof config !== "object") {
|
|
32
|
-
continue
|
|
33
|
-
}
|
|
34
|
-
const href = typeof config.href === "string" ? config.href.trim() : ""
|
|
35
|
-
if (!href) {
|
|
36
|
-
continue
|
|
37
|
-
}
|
|
38
|
-
normalized.push({
|
|
39
|
-
href,
|
|
40
|
-
match: normalizeInjectPatterns(config.match)
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
return normalized
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const resolveInjectMatchCandidates = (targetUrl) => {
|
|
47
|
-
if (typeof targetUrl !== "string") {
|
|
48
|
-
return []
|
|
49
|
-
}
|
|
50
|
-
const value = targetUrl.trim()
|
|
51
|
-
if (!value) {
|
|
52
|
-
return []
|
|
53
|
-
}
|
|
54
|
-
let parsed
|
|
55
|
-
try {
|
|
56
|
-
parsed = new URL(value)
|
|
57
|
-
} catch (_) {
|
|
58
|
-
return [value]
|
|
59
|
-
}
|
|
60
|
-
const pathname = parsed.pathname || ""
|
|
61
|
-
const originPath = `${parsed.origin}${pathname}`
|
|
62
|
-
const hostPath = `${parsed.host}${pathname}`
|
|
63
|
-
return [parsed.href, originPath, hostPath, pathname].filter(Boolean)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const matchesInjectPattern = (pattern, targetUrl) => {
|
|
67
|
-
if (pattern === "*") {
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
const candidates = resolveInjectMatchCandidates(targetUrl)
|
|
71
|
-
if (!candidates.length) {
|
|
72
|
-
return false
|
|
73
|
-
}
|
|
74
|
-
let expression
|
|
75
|
-
try {
|
|
76
|
-
expression = wildcardToRegex(pattern)
|
|
77
|
-
} catch (_) {
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
return candidates.some((candidate) => expression.test(candidate))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
8
|
const normalizeInjectHrefList = (value) => {
|
|
84
9
|
if (!value) {
|
|
85
10
|
return []
|
|
@@ -236,45 +161,7 @@ const createInjectRouter = ({ kernel }) => {
|
|
|
236
161
|
|
|
237
162
|
const frameUrl = typeof context.frameUrl === "string" ? context.frameUrl : ""
|
|
238
163
|
const frameInjectEntries = parseFrameInjectEntries(frameUrl)
|
|
239
|
-
if (frameInjectEntries.length
|
|
240
|
-
const scripts = []
|
|
241
|
-
for (const hrefRaw of frameInjectEntries) {
|
|
242
|
-
const launchUrl = await resolveInjectLaunchUrl({
|
|
243
|
-
workspace,
|
|
244
|
-
workspaceRoot,
|
|
245
|
-
launcher,
|
|
246
|
-
hrefRaw
|
|
247
|
-
})
|
|
248
|
-
if (!launchUrl) {
|
|
249
|
-
continue
|
|
250
|
-
}
|
|
251
|
-
scripts.push(launchUrl)
|
|
252
|
-
}
|
|
253
|
-
const uniqueScripts = [...new Set(scripts)]
|
|
254
|
-
if (uniqueScripts.length > 0) {
|
|
255
|
-
return {
|
|
256
|
-
status: 200,
|
|
257
|
-
body: {
|
|
258
|
-
ok: true,
|
|
259
|
-
matched: true,
|
|
260
|
-
workspace,
|
|
261
|
-
scripts: uniqueScripts,
|
|
262
|
-
source: "frame_query"
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
let injectConfig = launcher.script.inject
|
|
269
|
-
if (typeof injectConfig === "function") {
|
|
270
|
-
if (injectConfig.constructor.name === "AsyncFunction") {
|
|
271
|
-
injectConfig = await injectConfig(kernel, kernel.info)
|
|
272
|
-
} else {
|
|
273
|
-
injectConfig = injectConfig(kernel, kernel.info)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const entries = normalizeInjectEntries(injectConfig)
|
|
277
|
-
if (!entries.length) {
|
|
164
|
+
if (frameInjectEntries.length === 0) {
|
|
278
165
|
return {
|
|
279
166
|
status: 200,
|
|
280
167
|
body: {
|
|
@@ -282,21 +169,18 @@ const createInjectRouter = ({ kernel }) => {
|
|
|
282
169
|
matched: false,
|
|
283
170
|
workspace,
|
|
284
171
|
scripts: [],
|
|
285
|
-
reason: "
|
|
172
|
+
reason: "inject_not_requested"
|
|
286
173
|
}
|
|
287
174
|
}
|
|
288
175
|
}
|
|
289
176
|
|
|
290
177
|
const scripts = []
|
|
291
|
-
for (const
|
|
292
|
-
if (!entry.match.some((pattern) => matchesInjectPattern(pattern, frameUrl))) {
|
|
293
|
-
continue
|
|
294
|
-
}
|
|
178
|
+
for (const hrefRaw of frameInjectEntries) {
|
|
295
179
|
const launchUrl = await resolveInjectLaunchUrl({
|
|
296
180
|
workspace,
|
|
297
181
|
workspaceRoot,
|
|
298
182
|
launcher,
|
|
299
|
-
hrefRaw
|
|
183
|
+
hrefRaw
|
|
300
184
|
})
|
|
301
185
|
if (!launchUrl) {
|
|
302
186
|
continue
|
|
@@ -311,7 +195,8 @@ const createInjectRouter = ({ kernel }) => {
|
|
|
311
195
|
ok: true,
|
|
312
196
|
matched: uniqueScripts.length > 0,
|
|
313
197
|
workspace,
|
|
314
|
-
scripts: uniqueScripts
|
|
198
|
+
scripts: uniqueScripts,
|
|
199
|
+
source: "frame_query"
|
|
315
200
|
}
|
|
316
201
|
}
|
|
317
202
|
}
|
package/server/views/app.ejs
CHANGED
|
@@ -12243,7 +12243,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
12243
12243
|
const messageType = event.data.e
|
|
12244
12244
|
const isPinokioBridgeMessage = (
|
|
12245
12245
|
messageType === "pinokio:event" ||
|
|
12246
|
-
messageType === "pinokio:event-launch" ||
|
|
12247
12246
|
messageType === "pinokio:inject:request"
|
|
12248
12247
|
)
|
|
12249
12248
|
const trusted = isTrustedOrigin(event.origin) || (isPinokioBridgeMessage && isKnownFrameSource(event.source))
|
|
@@ -12276,14 +12275,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
12276
12275
|
})
|
|
12277
12276
|
}
|
|
12278
12277
|
}).catch(() => {})
|
|
12279
|
-
} else if (messageType === "pinokio:event-launch") {
|
|
12280
|
-
const payloadFrameUrl = event.data && event.data.context && typeof event.data.context.frameUrl === "string"
|
|
12281
|
-
? event.data.context.frameUrl
|
|
12282
|
-
: ""
|
|
12283
|
-
openEventLaunch(event.data && event.data.launch, {
|
|
12284
|
-
sourceWindow: event.source,
|
|
12285
|
-
sourceFrameUrl: payloadFrameUrl || resolveFrameUrlFromSource(event.source)
|
|
12286
|
-
})
|
|
12287
12278
|
} else if (messageType === "pinokio:inject:request") {
|
|
12288
12279
|
dispatchPinokioInjectRequest(event.data, event.source).then((result) => {
|
|
12289
12280
|
if (!result || !result.ok || !event.source || typeof event.source.postMessage !== "function") {
|