@ossy/cli 3.3.0 → 3.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/cli",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ossy-se/packages.git"
@@ -20,8 +20,8 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@babel/parser": "^7.28.6",
23
- "@ossy/app": "^3.3.0",
24
- "@ossy/sdk": "^3.3.0",
23
+ "@ossy/app": "^3.5.0",
24
+ "@ossy/sdk": "^3.5.0",
25
25
  "arg": "^5.0.2",
26
26
  "glob": "^13.0.6"
27
27
  },
@@ -33,5 +33,5 @@
33
33
  "/src",
34
34
  "README.md"
35
35
  ],
36
- "gitHead": "19e8bae4c1e9df79270218f28c0c9391f4f9871c"
36
+ "gitHead": "23167600f991596f122765a53f2b9df08314e115"
37
37
  }
@@ -184,9 +184,12 @@ export async function publish (options) {
184
184
  }
185
185
 
186
186
  try {
187
- await uploadFileToUrl(fileMeta, uploadUrl)
187
+ await uploadFileToUrl(fileMeta, uploadUrl, {
188
+ authorization: authToken,
189
+ workspaceId,
190
+ })
188
191
  } catch (err) {
189
- logError({ message: `[@ossy/cli] app publish: S3 PUT failed for ${f}: ${err.message}` })
192
+ logError({ message: `[@ossy/cli] app publish: PUT failed for ${f}: ${err.message}` })
190
193
  errors++
191
194
  return
192
195
  }
package/src/call/cli.js CHANGED
@@ -304,7 +304,10 @@ async function call (args) {
304
304
  const uploadUrl = result && result.content && result.content.uploadUrl
305
305
  if (uploadUrl) {
306
306
  try {
307
- await uploadFileToUrl(fileMeta, uploadUrl)
307
+ await uploadFileToUrl(fileMeta, uploadUrl, {
308
+ authorization: auth || undefined,
309
+ workspaceId: workspaceId || undefined,
310
+ })
308
311
  } catch (err) {
309
312
  process.stderr.write(`[@ossy/cli] call: upload PUT failed: ${err.message || err}\n`)
310
313
  process.exit(1)
package/src/file.js CHANGED
@@ -42,27 +42,51 @@ export function guessContentType (filePath) {
42
42
  }
43
43
 
44
44
  /**
45
- * PUT file bytes to a presigned S3 upload URL.
45
+ * Detect filesystem-backend upload URLs (`/local-storage?key=…`).
46
+ * S3 presigned URLs must not receive session cookies or Authorization headers.
47
+ * @param {string} url
48
+ * @returns {boolean}
49
+ */
50
+ export function isLocalStorageUploadUrl (url) {
51
+ if (!url || typeof url !== 'string') return false
52
+ try {
53
+ const parsed = new URL(url, 'http://localhost')
54
+ return parsed.pathname === '/local-storage' || parsed.pathname.endsWith('/local-storage')
55
+ } catch {
56
+ return false
57
+ }
58
+ }
59
+
60
+ /**
61
+ * PUT file bytes to an upload URL (S3 presigned or local-storage).
62
+ * For local-storage, pass authorization + workspaceId so the route can enforce permissions.
46
63
  * Throws on network error or non-2xx response.
47
64
  * @param {{ absPath: string, size: number, type: string }} fileMeta
48
65
  * @param {string} uploadUrl
66
+ * @param {{ authorization?: string, workspaceId?: string }} [auth]
49
67
  * @returns {Promise<void>}
50
68
  */
51
- export async function uploadFileToUrl (fileMeta, uploadUrl) {
69
+ export async function uploadFileToUrl (fileMeta, uploadUrl, auth = {}) {
52
70
  const { readFile } = await import('node:fs/promises')
53
71
  const body = await readFile(fileMeta.absPath)
72
+ /** @type {Record<string, string>} */
73
+ const headers = {
74
+ 'Content-Type': fileMeta.type,
75
+ 'Content-Length': String(fileMeta.size),
76
+ }
77
+ if (isLocalStorageUploadUrl(uploadUrl)) {
78
+ if (auth.authorization) headers.Authorization = auth.authorization
79
+ if (auth.workspaceId) headers.workspaceId = auth.workspaceId
80
+ }
54
81
  const res = await fetch(uploadUrl, {
55
82
  method: 'PUT',
56
- headers: {
57
- 'Content-Type': fileMeta.type,
58
- 'Content-Length': String(fileMeta.size),
59
- },
83
+ headers,
60
84
  body,
61
85
  })
62
86
  if (!res.ok) {
63
87
  const t = await res.text().catch(() => '')
64
88
  throw new Error(
65
- `S3 PUT failed: HTTP ${res.status}${t ? ' — ' + t.slice(0, 200) : ''}`
89
+ `Upload PUT failed: HTTP ${res.status}${t ? ' — ' + t.slice(0, 200) : ''}`
66
90
  )
67
91
  }
68
92
  }
@@ -252,10 +252,13 @@ export async function handler (args) {
252
252
  }
253
253
 
254
254
  try {
255
- await uploadFileToUrl(fileMeta, uploadUrl)
255
+ await uploadFileToUrl(fileMeta, uploadUrl, {
256
+ authorization: auth || undefined,
257
+ workspaceId: workspaceId || undefined,
258
+ })
256
259
  filesUploaded++
257
260
  } catch (err) {
258
- logError({ message: `[@ossy/cli] upload-dir: S3 PUT failed for ${f}: ${err.message}` })
261
+ logError({ message: `[@ossy/cli] upload-dir: PUT failed for ${f}: ${err.message}` })
259
262
  errors++
260
263
  }
261
264
  }