@ossy/storage 1.4.0 → 1.6.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 +2 -2
- package/src/local-storage.api.js +51 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/storage",
|
|
3
3
|
"description": "Analytics module — workspace analytics for website traffic",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"module": "./src/index.js",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ramda": "*",
|
|
31
31
|
"react": "*"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "24df2bde0d5d8794c5a82b9e802a2594ca73a5d9"
|
|
34
34
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LocalStorageClient } from '@ossy/platform'
|
|
2
|
+
import { createLogger } from '@ossy/observability'
|
|
3
|
+
|
|
4
|
+
const log = createLogger('local-storage')
|
|
5
|
+
|
|
6
|
+
export const metadata = {
|
|
7
|
+
id: 'local-storage',
|
|
8
|
+
path: '/local-storage',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default async function handle (req, res) {
|
|
12
|
+
const key = req.query?.key
|
|
13
|
+
if (!key || typeof key !== 'string') {
|
|
14
|
+
res.status(400).json({ error: 'Missing required query parameter: key' })
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// PUT — receive raw file bytes from CLI (same pattern as S3 presigned PUT)
|
|
19
|
+
if (req.method === 'PUT') {
|
|
20
|
+
try {
|
|
21
|
+
const chunks = []
|
|
22
|
+
for await (const chunk of req) chunks.push(chunk)
|
|
23
|
+
const body = Buffer.concat(chunks)
|
|
24
|
+
await LocalStorageClient.save(key, body)
|
|
25
|
+
res.status(200).end()
|
|
26
|
+
} catch (err) {
|
|
27
|
+
log.error('[local-storage] PUT failed', undefined, err)
|
|
28
|
+
res.status(500).json({ error: err.message })
|
|
29
|
+
}
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// GET — serve file bytes to runtime (same pattern as S3 presigned GET)
|
|
34
|
+
if (req.method === 'GET') {
|
|
35
|
+
try {
|
|
36
|
+
const { buffer, exists } = await LocalStorageClient.load(key)
|
|
37
|
+
if (!exists) {
|
|
38
|
+
res.status(404).end()
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
res.status(200).send(buffer)
|
|
42
|
+
} catch (err) {
|
|
43
|
+
log.error('[local-storage] GET failed', undefined, err)
|
|
44
|
+
res.status(500).json({ error: err.message })
|
|
45
|
+
}
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
res.setHeader('Allow', 'GET, PUT')
|
|
50
|
+
res.status(405).json({ error: 'Method Not Allowed' })
|
|
51
|
+
}
|