@ossy/storage 1.10.2 → 3.0.1

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/storage",
3
3
  "description": "Analytics module — workspace analytics for website traffic",
4
- "version": "1.10.2",
4
+ "version": "3.0.1",
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": "2b8745d57fee8b6c08787e2755b4df489291a5cd"
33
+ "gitHead": "4a70ec216448680d2fddc57b2a8a0077489720ae"
34
34
  }
package/src/Definition.js CHANGED
@@ -3,5 +3,5 @@ export const Definition = {
3
3
  title: 'Storage',
4
4
  description: 'Storage views and resource browsing inside workspaces.',
5
5
  icon: 'software-upload',
6
- statuses: ['beta'],
6
+ status: ['beta'],
7
7
  }
package/src/HeroCover.jsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { Title, Button, View, PageSection } from '@ossy/design-system'
2
+ import { Button, View, PageSection, Text } from '@ossy/design-system'
3
3
 
4
4
  const Cover = ({
5
5
  title,
@@ -20,13 +20,13 @@ const Cover = ({
20
20
  >
21
21
 
22
22
  <View gap="m" alignItems="center">
23
- <Title as="h1" variant="display" style={{ maxWidth: titleMaxWidth, textWrap: 'balance' }}>
23
+ <Text as="h1" variant="display" style={{ maxWidth: titleMaxWidth, textWrap: 'balance' }}>
24
24
  {title}
25
- </Title>
25
+ </Text>
26
26
 
27
- <Title as="h2" variant="title-tertiary" style={{ maxWidth: '800px' }}>
27
+ <Text as="h2" variant="heading-tertiary" style={{ maxWidth: '800px' }}>
28
28
  {text}
29
- </Title>
29
+ </Text>
30
30
  </View>
31
31
 
32
32
  <View gap="m" layout="row" justifyContent="center">
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react'
1
+ import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react'
2
2
  import { ListResources, createDirectory, moveResource, removeResource } from '@ossy/resources'
3
3
  import { GetWorkspace } from '@ossy/workspaces'
4
4
  import { AsyncStatus, useSdk } from '@ossy/sdk-react'
@@ -9,25 +9,9 @@ import {
9
9
  identity,
10
10
  last,
11
11
  } from 'ramda'
12
- import {
13
- Overlay,
14
- Switch,
15
- DropZone,
16
- Breadcrumbs,
17
- Guide,
18
- DelayedRender,
19
- useDocumentTitle,
20
- View,
21
- Button,
22
- ContextMenu,
23
- Dropdown,
24
- Title,
25
- Tags,
26
- EmptyState,
27
- useLocale,
28
- } from '@ossy/design-system'
29
- import { useActivePath, ResourcePanel, ResourceList, ResourceDialogMove } from '@ossy/resources'
30
- import { useRouter } from '@ossy/router-react'
12
+ import { Text, Overlay, Switch, DropZone, Breadcrumbs, Guide, DelayedRender, useDocumentTitle, View, Button, ContextMenu, Dropdown, EmptyState, Page, Tags, useLocale, preloadStorageIcons } from '@ossy/design-system'
13
+ import { useActivePath, ResourcePanel, ResourceList, ResourceDialogMove, useSelectedResourceId } from '@ossy/resources'
14
+ import { useRouter, useSearchParams } from '@ossy/router-react'
31
15
 
32
16
  const Path = ({ path, ...props }) => (
33
17
  <Button variant="command" {...props}>
@@ -51,19 +35,40 @@ const Overlays = {
51
35
 
52
36
  export const ResourcesPage = () => {
53
37
  const router = useRouter()
38
+ const searchParams = useSearchParams()
54
39
  const { t } = useLocale()
55
40
  const sdk = useSdk()
56
41
  const { data: workspace = {} } = sdk.read(GetWorkspace)
57
42
  const [overlay, setOverlay] = useState(Overlays.None)
58
- const [selectedResourceId, setSelectedResourceId] = useState()
59
- const [resourcesListStatus, setResourcesListStatus] = useState(ResourcesListStatus.Loading)
43
+ const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
60
44
  const activePath = useActivePath()
45
+ const lastSuccessfulResourcesRef = useRef([])
46
+
47
+ useEffect(() => {
48
+ preloadStorageIcons()
49
+ }, [])
61
50
 
62
51
  const {
63
52
  status: resourcesStatus,
64
53
  data: resources = [],
65
54
  } = sdk.read(ListResources, { location: activePath })
66
55
 
56
+ if (resourcesStatus === AsyncStatus.Success) {
57
+ lastSuccessfulResourcesRef.current = resources
58
+ }
59
+
60
+ const displayResources =
61
+ resourcesStatus === AsyncStatus.Success ? resources : lastSuccessfulResourcesRef.current
62
+
63
+ const resourcesListStatus = useMemo(() => {
64
+ if (resourcesStatus === AsyncStatus.Error) return ResourcesListStatus.Error
65
+ if (resourcesStatus === AsyncStatus.Success) {
66
+ return resources.length === 0 ? ResourcesListStatus.Empty : ResourcesListStatus.Success
67
+ }
68
+ if (displayResources.length > 0) return ResourcesListStatus.Success
69
+ return ResourcesListStatus.Loading
70
+ }, [resourcesStatus, resources.length, displayResources.length])
71
+
67
72
  const [isCreatingFolder, setIsCreatingFolder] = useState(false)
68
73
  const [newFolderName, setNewFolderName] = useState(() => t('storage.resources.newFolderDefault'))
69
74
 
@@ -91,9 +96,29 @@ export const ResourcesPage = () => {
91
96
 
92
97
  useDocumentTitle(workspace.name || 'loading workspace')
93
98
 
94
- const goTo = x => () => {
95
- router.searchParams.set('location', `${x}/`)
96
- }
99
+ const storageHomeHref = useCallback((locationQuery = '') => {
100
+ const parts = []
101
+ if (locationQuery) parts.push(locationQuery)
102
+ if (selectedResourceId) parts.push(`r=${selectedResourceId}`)
103
+ const search = parts.length ? `?${parts.join('&')}` : ''
104
+ return router.getHref(`@storage/home${search}`)
105
+ }, [router, selectedResourceId])
106
+
107
+ const navigateToLocation = useCallback((locationPath) => {
108
+ const normalized = locationPath.startsWith('/') ? locationPath : `/${locationPath}`
109
+ const withSlash = normalized.endsWith('/') ? normalized : `${normalized}/`
110
+ searchParams.set('location', withSlash)
111
+ }, [searchParams.set])
112
+
113
+ const openLocation = useCallback((locationPath) => (event) => {
114
+ if (event?.metaKey || event?.ctrlKey || event?.shiftKey || event?.button === 1) return
115
+ event?.preventDefault?.()
116
+ navigateToLocation(locationPath)
117
+ }, [navigateToLocation])
118
+
119
+ const goTo = useCallback((path) => () => {
120
+ navigateToLocation(path)
121
+ }, [navigateToLocation])
97
122
 
98
123
  const onMoveResource = newLocation => resourceId => {
99
124
  moveResource(sdk, resourceId, newLocation, activePath)
@@ -121,41 +146,29 @@ export const ResourcesPage = () => {
121
146
  const isLast = i === (paths.length - 1)
122
147
  if (isLast) return <Path key={path} path={path} onClick={goTo(path)} />
123
148
  return (
124
- <DropZone onDrop={onMoveResource(`${path}/`)}>
125
- <Path key={path} path={path} href={router.getHref(`@storage/home?location=${path}`)}/>
149
+ <DropZone onDrop={onMoveResource(`${path}/`)} key={path}>
150
+ <Path path={path} onClick={openLocation(`${path}/`)} href={storageHomeHref(`location=${path}`)} />
126
151
  </DropZone>
127
152
  )
128
153
  })
129
154
  )(activePath)
130
155
 
131
- useEffect(() => {
132
- if (resourcesStatus === AsyncStatus.NotInitialized) {
133
- setResourcesListStatus(ResourcesListStatus.Loading)
134
- } else if (resourcesStatus === AsyncStatus.Loading) {
135
- setResourcesListStatus(ResourcesListStatus.Loading)
136
- } else if (resourcesStatus === AsyncStatus.Error) {
137
- setResourcesListStatus(ResourcesListStatus.Error)
138
- } else if (resourcesStatus === AsyncStatus.Success) {
139
- resources.length === 0
140
- ? setResourcesListStatus(ResourcesListStatus.Empty)
141
- : setResourcesListStatus(ResourcesListStatus.Success)
142
- }
143
- }, [resources, resourcesStatus])
144
-
145
- const filterResources = resources
156
+ const filterResources = useMemo(() => displayResources
146
157
  //filter out the @ossy resources, it is resources that the system creates
147
158
  .filter(resource => !resource?.name?.startsWith?.('@ossy'))
148
159
  .map(resource => {
149
160
 
150
161
  if (resource.type === 'directory') {
162
+ const folderLocation = `${activePath}${resource.name}`
151
163
  return {
152
164
  ...resource,
153
- href: router.getHref(`@storage/home?location=${activePath}${resource.name}`),
165
+ href: storageHomeHref(`location=${folderLocation}`),
166
+ onClick: openLocation(folderLocation),
154
167
  onDrop: onMoveResource(`${resource.location}${resource.name}/`),
155
168
  actions: [
156
169
  <ContextMenu.Item
157
170
  prefix="mail-forward"
158
- href={router.getHref(`@storage/home?location=${activePath}${resource.name}`)}
171
+ href={storageHomeHref(`location=${activePath}${resource.name}`)}
159
172
  onClick={event => { event.stopPropagation() }}
160
173
  key="details"
161
174
  >
@@ -221,11 +234,10 @@ export const ResourcesPage = () => {
221
234
  .sort((a, b) => {
222
235
  if (a.type === 'directory' && b.type !== 'directory') return -1
223
236
  if (a.type !== 'directory' && b.type === 'directory') return 1
224
- })
237
+ }), [displayResources, activePath, storageHomeHref, openLocation, onMoveResource, onRemoveResource, setSelectedResourceId, t])
225
238
 
226
239
  return (
227
- <View style={{ height: '100%' }}>
228
-
240
+ <>
229
241
  <style>
230
242
  {`
231
243
  [data-scrollbar="hide"] {
@@ -240,15 +252,15 @@ export const ResourcesPage = () => {
240
252
  `}
241
253
  </style>
242
254
 
243
- <View layout="row" inset="m" justifyContent="space-between" alignItems="center" surface="primary" roundness="s" style={{ flexShrink: 0 }}>
244
- <View layout='row' gap="s" alignItems="center">
245
- <Title>{t('storage.resources.title')}</Title>
255
+ <Page
256
+ inset="none"
257
+ title="storage.resources.title"
258
+ description="storage.resources.description"
259
+ near={<Tags tags={[t('storage.resources.beta')]} size="s" />}
260
+ style={{ minHeight: 0 }}
261
+ >
246
262
 
247
- <Tags size="s" tags={[t('storage.resources.beta')]} />
248
- </View>
249
- </View>
250
-
251
- <View stack horizontal gap="xs" style={{ flexGrow: 1 }}>
263
+ <View stack horizontal gap="xs" style={{ flexGrow: 1, minHeight: 0 }}>
252
264
 
253
265
  <View.Item fill surface="primary" roundness="xs" >
254
266
  <View stack bordered style={{ height: '100%' }}>
@@ -267,20 +279,14 @@ export const ResourcesPage = () => {
267
279
  >
268
280
 
269
281
  <Breadcrumbs>
270
- {
271
- activePath === '/'
272
- ? <Button prefix="home-alt" variant="command" href={router.getHref('@storage/home')} />
273
- : (
274
- <DropZone onDrop={onMoveResource('/')}>
275
- <Button prefix="home-alt" variant="command" href={router.getHref('@storage/home')} />
276
- </DropZone>
277
- )
278
- }
282
+ <DropZone onDrop={activePath === '/' ? undefined : onMoveResource('/')}>
283
+ <Button prefix="home-alt" variant="command" onClick={openLocation('/')} href={storageHomeHref()} />
284
+ </DropZone>
279
285
 
280
286
  { activePath !== '/' && getActivePath() }
281
287
  </Breadcrumbs>
282
288
 
283
- <Dropdown trigger={<Button prefix="add" variant="command" style={{ height: '32px' }}>{t('storage.resources.add')}</Button>}>
289
+ <Dropdown trigger={<Button prefix="add" variant="command" style={{ height: '32px' }} label="storage.resources.add" />}>
284
290
  <View inset="xs" surface="primary" roundness="s">
285
291
  <ContextMenu roundness="s" surface="primary">
286
292
  <ContextMenu.Item
@@ -310,7 +316,7 @@ export const ResourcesPage = () => {
310
316
  <Switch.Case match={[ResourcesListStatus.Error]}>
311
317
  <View layout="off-center" style={{ height: '100%' }}>
312
318
  <Guide
313
- slot="content"
319
+ data-region="content"
314
320
  title={t('storage.resources.errorTitle')}
315
321
  text={t('storage.resources.errorText')}
316
322
  style={{ width: '100vw', maxWidth: '350px' }}
@@ -330,8 +336,9 @@ export const ResourcesPage = () => {
330
336
  <span
331
337
  className="inline-m"
332
338
  style={{
333
- width: '20px',
334
- height: '18px',
339
+ width: '24px',
340
+ height: '24px',
341
+ flexShrink: 0,
335
342
  background: 'hsl(0, 0%, 50%)',
336
343
  borderRadius: '16px'
337
344
  }}
@@ -368,7 +375,7 @@ export const ResourcesPage = () => {
368
375
  </View>
369
376
  </View.Item>
370
377
 
371
- <ResourcePanel resourceId={selectedResourceId} onClose={() => setSelectedResourceId(undefined)} />
378
+ <ResourcePanel resourceId={selectedResourceId} onClose={clearSelectedResourceId} />
372
379
 
373
380
  </View>
374
381
 
@@ -377,7 +384,7 @@ export const ResourcesPage = () => {
377
384
  overlay === Overlays.RemoveDirectory && (
378
385
  <Overlay isVisible={true} onClose={() => setOverlay(Overlays.None)}>
379
386
  <View layout="off-center-s" style={{ height: '100%' }}>
380
- <View slot="content">
387
+ <View data-region="content">
381
388
  <View surface="primary" roundness="s">
382
389
  <View surface="primary" inset="l" roundness="s">
383
390
  <Guide
@@ -407,7 +414,8 @@ export const ResourcesPage = () => {
407
414
  )
408
415
  }
409
416
 
410
- </View>
417
+ </Page>
418
+ </>
411
419
  )
412
420
  }
413
421
 
@@ -1,12 +1,5 @@
1
1
  import React from 'react'
2
- import {
3
- Title,
4
- Text,
5
- View,
6
- Icon,
7
- PageSection,
8
- MarkdownViewer
9
- } from '@ossy/design-system'
2
+ import { Text, View, Icon, PageSection, MarkdownViewer } from '@ossy/design-system'
10
3
  import { HeroCover } from './HeroCover.jsx'
11
4
 
12
5
  export default ({
@@ -22,9 +15,9 @@ export default ({
22
15
 
23
16
  <View gap="m" inset="s">
24
17
 
25
- <Title variant="secondary">
18
+ <Text variant="heading-secondary" as="h2">
26
19
  Overview
27
- </Title>
20
+ </Text>
28
21
 
29
22
  <View gap="m" layout="row-wrap">
30
23
  {features.map(x => (
@@ -51,9 +44,9 @@ export default ({
51
44
  </View>
52
45
 
53
46
  <View gap="m" inset="s">
54
- <Title variant="secondary">
47
+ <Text variant="heading-secondary" as="h2">
55
48
  Features
56
- </Title>
49
+ </Text>
57
50
 
58
51
  {features.map(x => (
59
52
  <View key={x.title} roundness="m" gap="m" inset="l" style={{
@@ -64,9 +57,9 @@ export default ({
64
57
  <View justifyContent="center" alignItems="center">
65
58
  <Icon name={x.icon} size="m" />
66
59
  </View>
67
- <Title variant="tertiary">
60
+ <Text variant="heading-tertiary" as="h3">
68
61
  {x.title}
69
- </Title>
62
+ </Text>
70
63
  </View>
71
64
 
72
65
  <Text>{x.text}</Text>
@@ -3,6 +3,7 @@
3
3
  "storage.home.cover.title": "Storage",
4
4
  "storage.home.cover.text": "Managing content should be easy",
5
5
  "storage.resources.title": "Storage",
6
+ "storage.resources.description": "Browse, upload, and organize files in your workspace.",
6
7
  "storage.resources.beta": "Beta",
7
8
  "storage.resources.add": "Add",
8
9
  "storage.resources.createFolder": "Create folder",
@@ -1,27 +1,56 @@
1
- import { LocalStorageClient } from '@ossy/platform'
1
+ import { StorageClient } from '@ossy/platform'
2
+ import { assertStorageKey } from '@ossy/platform/storage-keys'
2
3
  import { createLogger } from '@ossy/observability'
3
4
 
4
5
  const log = createLogger('local-storage')
5
6
 
7
+ function contentTypeFromBuffer (buffer) {
8
+ if (!buffer || buffer.length < 4) return null
9
+ if (buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4e && buffer[3] === 0x47) {
10
+ return 'image/png'
11
+ }
12
+ if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) {
13
+ return 'image/jpeg'
14
+ }
15
+ if (buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46) {
16
+ return 'image/gif'
17
+ }
18
+ if (buffer.length >= 12 && buffer.toString('ascii', 0, 4) === 'RIFF' && buffer.toString('ascii', 8, 12) === 'WEBP') {
19
+ return 'image/webp'
20
+ }
21
+ if (buffer[0] === 0x25 && buffer[1] === 0x50 && buffer[2] === 0x44 && buffer[3] === 0x46) {
22
+ return 'application/pdf'
23
+ }
24
+ return null
25
+ }
26
+
6
27
  export const metadata = {
7
28
  id: 'local-storage',
8
29
  path: '/local-storage',
9
30
  }
10
31
 
11
32
  export default async function handle (req, res) {
12
- const key = req.query?.key
13
- if (!key || typeof key !== 'string') {
33
+ const rawKey = req.query?.key
34
+ if (!rawKey || typeof rawKey !== 'string') {
14
35
  res.status(400).json({ error: 'Missing required query parameter: key' })
15
36
  return
16
37
  }
17
38
 
39
+ let key
40
+ try {
41
+ key = assertStorageKey(rawKey)
42
+ } catch (err) {
43
+ res.status(400).json({ error: err.message })
44
+ return
45
+ }
46
+
18
47
  // PUT — receive raw file bytes from CLI (same pattern as S3 presigned PUT)
19
48
  if (req.method === 'PUT') {
20
49
  try {
21
50
  const chunks = []
22
51
  for await (const chunk of req) chunks.push(chunk)
23
52
  const body = Buffer.concat(chunks)
24
- await LocalStorageClient.save(key, body)
53
+ await StorageClient.save(key, body)
25
54
  res.status(200).end()
26
55
  } catch (err) {
27
56
  log.error('[local-storage] PUT failed', undefined, err)
@@ -33,11 +62,13 @@ export default async function handle (req, res) {
33
62
  // GET — serve file bytes to runtime (same pattern as S3 presigned GET)
34
63
  if (req.method === 'GET') {
35
64
  try {
36
- const { buffer, exists } = await LocalStorageClient.load(key)
65
+ const { buffer, exists } = await StorageClient.load(key)
37
66
  if (!exists) {
38
67
  res.status(404).end()
39
68
  return
40
69
  }
70
+ const contentType = contentTypeFromBuffer(buffer)
71
+ if (contentType) res.setHeader('Content-Type', contentType)
41
72
  res.status(200).send(buffer)
42
73
  } catch (err) {
43
74
  log.error('[local-storage] GET failed', undefined, err)
@@ -3,6 +3,7 @@
3
3
  "storage.home.cover.title": "Storage",
4
4
  "storage.home.cover.text": "Det ska vara enkelt att hantera innehåll",
5
5
  "storage.resources.title": "Storage",
6
+ "storage.resources.description": "Bläddra, ladda upp och organisera filer i din workspace.",
6
7
  "storage.resources.beta": "Beta",
7
8
  "storage.resources.add": "Lägg till",
8
9
  "storage.resources.createFolder": "Skapa mapp",