pinokiod 5.3.10 → 5.3.12
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/index.js +86 -2
- package/server/views/registry_checkin.ejs +4 -0
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -4860,6 +4860,8 @@ class Server {
|
|
|
4860
4860
|
const returnRaw = typeof req.query.return === 'string' ? req.query.return.trim() : ''
|
|
4861
4861
|
const successRaw = typeof req.query.success === 'string' ? req.query.success.trim() : ''
|
|
4862
4862
|
const appSlug = typeof req.query.app === 'string' ? req.query.app.trim() : ''
|
|
4863
|
+
const registryRaw = typeof req.query.registry === 'string' ? req.query.registry.trim() : ''
|
|
4864
|
+
const connectRaw = typeof req.query.connectUrl === 'string' ? req.query.connectUrl.trim() : ''
|
|
4863
4865
|
const registryEnabled = await this.isRegistryEnabled().catch(() => false)
|
|
4864
4866
|
|
|
4865
4867
|
let returnUrl = null
|
|
@@ -4877,6 +4879,65 @@ class Server {
|
|
|
4877
4879
|
} catch (_) {}
|
|
4878
4880
|
}
|
|
4879
4881
|
|
|
4882
|
+
const normalizeHttpUrl = (value) => {
|
|
4883
|
+
if (!value) return null
|
|
4884
|
+
try {
|
|
4885
|
+
const u = new URL(String(value))
|
|
4886
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null
|
|
4887
|
+
u.hash = ''
|
|
4888
|
+
return u.toString().replace(/\/$/, '')
|
|
4889
|
+
} catch (_) {
|
|
4890
|
+
return null
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
const isLocalHost = (hostname) => ['localhost', '127.0.0.1', '0.0.0.0'].includes(String(hostname || '').toLowerCase())
|
|
4894
|
+
const hostMatches = (a, b) => a && b && a.protocol === b.protocol && a.hostname === b.hostname
|
|
4895
|
+
const baseDomain = (hostname) => {
|
|
4896
|
+
const parts = String(hostname || '').toLowerCase().split('.').filter(Boolean)
|
|
4897
|
+
if (parts.length <= 2) return parts.join('.')
|
|
4898
|
+
return parts.slice(-2).join('.')
|
|
4899
|
+
}
|
|
4900
|
+
const sameBaseDomain = (a, b) => {
|
|
4901
|
+
const ha = String(a || '').toLowerCase()
|
|
4902
|
+
const hb = String(b || '').toLowerCase()
|
|
4903
|
+
if (!ha || !hb) return false
|
|
4904
|
+
if (isLocalHost(ha) && isLocalHost(hb)) return true
|
|
4905
|
+
return baseDomain(ha) === baseDomain(hb)
|
|
4906
|
+
}
|
|
4907
|
+
|
|
4908
|
+
const registryRawPresent = !!registryRaw
|
|
4909
|
+
const connectRawPresent = !!connectRaw
|
|
4910
|
+
let registryOverride = normalizeHttpUrl(registryRaw)
|
|
4911
|
+
let connectOverride = normalizeHttpUrl(connectRaw)
|
|
4912
|
+
if (returnUrl) {
|
|
4913
|
+
try {
|
|
4914
|
+
const returnHost = new URL(returnUrl)
|
|
4915
|
+
const returnOrigin = returnHost.origin
|
|
4916
|
+
if (registryOverride) {
|
|
4917
|
+
const regHost = new URL(registryOverride)
|
|
4918
|
+
const ok = hostMatches(regHost, returnHost)
|
|
4919
|
+
|| sameBaseDomain(regHost.hostname, returnHost.hostname)
|
|
4920
|
+
if (!ok) registryOverride = null
|
|
4921
|
+
}
|
|
4922
|
+
if (connectOverride) {
|
|
4923
|
+
const conHost = new URL(connectOverride)
|
|
4924
|
+
const ok = hostMatches(conHost, returnHost)
|
|
4925
|
+
|| sameBaseDomain(conHost.hostname, returnHost.hostname)
|
|
4926
|
+
if (!ok) connectOverride = null
|
|
4927
|
+
}
|
|
4928
|
+
if (!registryOverride && !registryRawPresent && returnOrigin) {
|
|
4929
|
+
registryOverride = returnOrigin
|
|
4930
|
+
}
|
|
4931
|
+
if (!connectOverride && !connectRawPresent && returnOrigin) {
|
|
4932
|
+
connectOverride = `${returnOrigin.replace(/\/$/, '')}/connect/pinokio`
|
|
4933
|
+
}
|
|
4934
|
+
} catch (_) {}
|
|
4935
|
+
} else {
|
|
4936
|
+
registryOverride = null
|
|
4937
|
+
connectOverride = null
|
|
4938
|
+
}
|
|
4939
|
+
console.log("[registry/checkin] repo=%s return=%s registryRaw=%s connectRaw=%s registryOverride=%s connectOverride=%s", repoUrl || "", returnUrl || "", registryRaw || "", connectRaw || "", registryOverride || "", connectOverride || "")
|
|
4940
|
+
|
|
4880
4941
|
let candidates = []
|
|
4881
4942
|
if (repoUrl && this.kernel && this.kernel.git) {
|
|
4882
4943
|
const apiRoot = this.kernel.path('api')
|
|
@@ -4923,6 +4984,8 @@ class Server {
|
|
|
4923
4984
|
returnUrl,
|
|
4924
4985
|
successUrl,
|
|
4925
4986
|
registryEnabled: !!registryEnabled,
|
|
4987
|
+
registryOverride,
|
|
4988
|
+
connectOverride,
|
|
4926
4989
|
candidates,
|
|
4927
4990
|
}
|
|
4928
4991
|
const dataJson = JSON.stringify(data).replace(/</g, '\\u003c')
|
|
@@ -5150,6 +5213,19 @@ class Server {
|
|
|
5150
5213
|
res.json({ ok: false })
|
|
5151
5214
|
return
|
|
5152
5215
|
}
|
|
5216
|
+
const normalizeHttpUrl = (value) => {
|
|
5217
|
+
if (!value) return null
|
|
5218
|
+
try {
|
|
5219
|
+
const u = new URL(String(value))
|
|
5220
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null
|
|
5221
|
+
u.hash = ''
|
|
5222
|
+
return u.toString().replace(/\/$/, '')
|
|
5223
|
+
} catch (_) {
|
|
5224
|
+
return null
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5227
|
+
const registryOverride = normalizeHttpUrl(typeof req.query.registry === 'string' ? req.query.registry.trim() : '')
|
|
5228
|
+
const connectOverride = normalizeHttpUrl(typeof req.query.connectUrl === 'string' ? req.query.connectUrl.trim() : '')
|
|
5153
5229
|
const registryEnabled = await this.isRegistryEnabled().catch(() => false)
|
|
5154
5230
|
const publishRaw = typeof req.query.publish === 'string' ? req.query.publish.trim().toLowerCase() : ''
|
|
5155
5231
|
const wantPublish = registryEnabled && (publishRaw === '1' || publishRaw === 'true' || publishRaw === 'cloud')
|
|
@@ -5165,9 +5241,17 @@ class Server {
|
|
|
5165
5241
|
if (created && created.remoteKey && created.id && created.hash) {
|
|
5166
5242
|
if (wantPublish) {
|
|
5167
5243
|
const registry = await this.getRegistryConfig()
|
|
5168
|
-
const baseUrl = registry && registry.url ? String(registry.url).replace(/\/$/, '') : null
|
|
5244
|
+
const baseUrl = registryOverride || (registry && registry.url ? String(registry.url).replace(/\/$/, '') : null)
|
|
5169
5245
|
const apiKey = registry && registry.apiKey ? String(registry.apiKey) : null
|
|
5170
|
-
|
|
5246
|
+
let connectUrl = connectOverride
|
|
5247
|
+
if (!connectUrl) {
|
|
5248
|
+
if (registryOverride) {
|
|
5249
|
+
connectUrl = `${registryOverride.replace(/\/$/, '')}/connect/pinokio`
|
|
5250
|
+
} else {
|
|
5251
|
+
connectUrl = await this.getRegistryConnectUrl().catch(() => null)
|
|
5252
|
+
}
|
|
5253
|
+
}
|
|
5254
|
+
console.log("[checkpoints/snapshot] publish=1 registryOverride=%s baseUrl=%s connectUrl=%s hasApiKey=%s", registryOverride || "", baseUrl || "", connectUrl || "", apiKey ? "yes" : "no")
|
|
5171
5255
|
if (!baseUrl || !apiKey) {
|
|
5172
5256
|
await this.kernel.git.setCheckpointSync(created.remoteKey, created.id, { status: "needs_link", at: Date.now() }).catch(() => {})
|
|
5173
5257
|
res.json({ ok: true, created: created || null, publish: { ok: false, code: "not_linked", connectUrl } })
|
|
@@ -129,6 +129,8 @@
|
|
|
129
129
|
|
|
130
130
|
<script>
|
|
131
131
|
const data = <%- dataJson %>;
|
|
132
|
+
const registryOverride = data.registryOverride || null;
|
|
133
|
+
const connectOverride = data.connectOverride || null;
|
|
132
134
|
const repoEl = document.getElementById('repo');
|
|
133
135
|
const statusEl = document.getElementById('status');
|
|
134
136
|
const pickerEl = document.getElementById('picker');
|
|
@@ -258,6 +260,8 @@
|
|
|
258
260
|
if (cancelBtn) cancelBtn.disabled = true;
|
|
259
261
|
try {
|
|
260
262
|
const qs = new URLSearchParams({ workspace: folder, publish: '1' });
|
|
263
|
+
if (registryOverride) qs.set('registry', registryOverride);
|
|
264
|
+
if (connectOverride) qs.set('connectUrl', connectOverride);
|
|
261
265
|
const res = await fetch(`/checkpoints/snapshot?${qs.toString()}`, {
|
|
262
266
|
method: 'POST',
|
|
263
267
|
headers: { 'Accept': 'application/json' }
|