@ossy/storage 3.4.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/storage",
3
3
  "description": "Analytics module — workspace analytics for website traffic",
4
- "version": "3.4.0",
4
+ "version": "3.5.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": "d36b69444268d172bc3e8e1dc77e67afc63f8650"
33
+ "gitHead": "23167600f991596f122765a53f2b9df08314e115"
34
34
  }
@@ -1,5 +1,17 @@
1
1
  import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react'
2
- import { ListResources, createDirectory, moveResource, removeResource, uploadFile } from '@ossy/resources'
2
+ import {
3
+ ListResources,
4
+ applyResourceSelectionGesture,
5
+ createDirectory,
6
+ filterDownloadableResources,
7
+ isDownloadableResource,
8
+ isMultiSelectGesture,
9
+ moveResource,
10
+ removeResource,
11
+ resourceDownloadHref,
12
+ triggerResourceDownloads,
13
+ uploadFile,
14
+ } from '@ossy/resources'
3
15
  import { GetWorkspace } from '@ossy/workspaces'
4
16
  import { AsyncStatus, useSdk } from '@ossy/sdk-react'
5
17
  import {
@@ -30,6 +42,7 @@ const ResourcesListStatus = {
30
42
  const Overlays = {
31
43
  None: 'None',
32
44
  Removedirectory : 'RemoveDirectory',
45
+ RemoveBatch: 'RemoveBatch',
33
46
  MoveResource: 'MoveResource'
34
47
  }
35
48
 
@@ -48,6 +61,9 @@ export const ResourcesPage = () => {
48
61
  const [viewMode, setViewMode] = useState(ViewMode.List)
49
62
  const [addMenuOpen, setAddMenuOpen] = useState(false)
50
63
  const [addMenuPosition, setAddMenuPosition] = useState(null)
64
+ const [batchSelectedIds, setBatchSelectedIds] = useState(() => new Set())
65
+ const [selectionAnchorId, setSelectionAnchorId] = useState(null)
66
+ const [selectionMode, setSelectionMode] = useState(false)
51
67
  const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
52
68
  const activePath = useActivePath()
53
69
  const lastSuccessfulResourcesRef = useRef([])
@@ -56,6 +72,12 @@ export const ResourcesPage = () => {
56
72
  preloadStorageIcons()
57
73
  }, [])
58
74
 
75
+ useEffect(() => {
76
+ setBatchSelectedIds(new Set())
77
+ setSelectionAnchorId(null)
78
+ setSelectionMode(false)
79
+ }, [activePath])
80
+
59
81
  const {
60
82
  status: resourcesStatus,
61
83
  data: resources = [],
@@ -150,6 +172,26 @@ export const ResourcesPage = () => {
150
172
 
151
173
  }
152
174
 
175
+ const clearBatchSelection = useCallback(() => {
176
+ setBatchSelectedIds(new Set())
177
+ setSelectionAnchorId(null)
178
+ }, [])
179
+
180
+ const exitSelectionMode = useCallback(() => {
181
+ setSelectionMode(false)
182
+ clearBatchSelection()
183
+ }, [clearBatchSelection])
184
+
185
+ const enterSelectionMode = useCallback(() => {
186
+ setSelectionMode(true)
187
+ clearSelectedResourceId()
188
+ }, [clearSelectedResourceId])
189
+
190
+ const toggleSelectionMode = useCallback(() => {
191
+ if (selectionMode) exitSelectionMode()
192
+ else enterSelectionMode()
193
+ }, [selectionMode, exitSelectionMode, enterSelectionMode])
194
+
153
195
  const openCreateFolder = useCallback(() => {
154
196
  setIsCreatingFolder(true)
155
197
  setNewFolderName(t('storage.resources.newFolderDefault'))
@@ -222,7 +264,10 @@ export const ResourcesPage = () => {
222
264
  return {
223
265
  ...resource,
224
266
  href: storageHomeHref(`location=${folderLocation}`),
225
- onClick: openLocation(folderLocation),
267
+ onClick: (item, event) => {
268
+ if (isMultiSelectGesture(event)) return
269
+ openLocation(folderLocation)(event)
270
+ },
226
271
  onDrop: onMoveResource(dropLocation),
227
272
  onFilesDrop: onUploadFiles(dropLocation),
228
273
  actions: [
@@ -245,10 +290,17 @@ export const ResourcesPage = () => {
245
290
  }
246
291
  }
247
292
 
293
+ const downloadHref = isDownloadableResource(resource)
294
+ ? resourceDownloadHref(resource)
295
+ : null
296
+
248
297
  return {
249
298
  ...resource,
250
299
  dragData: resource.id,
251
- onClick: () => setSelectedResourceId(resource.id),
300
+ onClick: (item, event) => {
301
+ if (isMultiSelectGesture(event)) return
302
+ setSelectedResourceId(resource.id)
303
+ },
252
304
  actions: [
253
305
  <ContextMenu.Item
254
306
  key="details"
@@ -257,6 +309,18 @@ export const ResourcesPage = () => {
257
309
  >
258
310
  View
259
311
  </ContextMenu.Item>,
312
+ ...(downloadHref
313
+ ? [
314
+ <ContextMenu.Item
315
+ key="download"
316
+ prefix="software-download"
317
+ href={downloadHref}
318
+ download={resource.name}
319
+ >
320
+ {t('storage.resources.download')}
321
+ </ContextMenu.Item>,
322
+ ]
323
+ : []),
260
324
  <ContextMenu.Item
261
325
  key="move"
262
326
  prefix="details-more"
@@ -286,6 +350,107 @@ export const ResourcesPage = () => {
286
350
  if (!aDir && bDir) return 1
287
351
  }), [displayResources, activePath, storageHomeHref, openLocation, onMoveResource, onUploadFiles, onRemoveResource, setSelectedResourceId, t])
288
352
 
353
+ const orderedResourceIds = useMemo(
354
+ () => filterResources.map((resource) => resource.id).filter(Boolean),
355
+ [filterResources],
356
+ )
357
+
358
+ const highlightedIds = useMemo(() => {
359
+ if (batchSelectedIds.size > 0) return batchSelectedIds
360
+ return selectedResourceId ? new Set([selectedResourceId]) : new Set()
361
+ }, [batchSelectedIds, selectedResourceId])
362
+
363
+ const selectedDownloadableResources = useMemo(() => {
364
+ if (batchSelectedIds.size === 0) return []
365
+ return filterDownloadableResources(
366
+ filterResources.filter((resource) => batchSelectedIds.has(resource.id)),
367
+ )
368
+ }, [batchSelectedIds, filterResources])
369
+
370
+ const selectedBatchResources = useMemo(() => {
371
+ if (batchSelectedIds.size === 0) return []
372
+ return filterResources.filter((resource) => batchSelectedIds.has(resource.id))
373
+ }, [batchSelectedIds, filterResources])
374
+
375
+ const handleResourceActivate = useCallback((resource, event) => {
376
+ if (!resource?.id) return
377
+
378
+ if (selectionMode || isMultiSelectGesture(event)) {
379
+ event?.preventDefault?.()
380
+ const gestureEvent = selectionMode && !isMultiSelectGesture(event)
381
+ ? { metaKey: true }
382
+ : event
383
+ const { nextSelectedIds, nextAnchorId } = applyResourceSelectionGesture({
384
+ selectedIds: batchSelectedIds,
385
+ orderedIds: orderedResourceIds,
386
+ targetId: resource.id,
387
+ event: gestureEvent,
388
+ anchorId: selectionAnchorId,
389
+ })
390
+ setBatchSelectedIds(nextSelectedIds)
391
+ setSelectionAnchorId(nextAnchorId)
392
+ if (!selectionMode) setSelectionMode(true)
393
+ clearSelectedResourceId()
394
+ return
395
+ }
396
+
397
+ clearBatchSelection()
398
+ }, [
399
+ selectionMode,
400
+ batchSelectedIds,
401
+ orderedResourceIds,
402
+ selectionAnchorId,
403
+ clearSelectedResourceId,
404
+ clearBatchSelection,
405
+ ])
406
+
407
+ const handleToggleSelect = useCallback((resource) => {
408
+ if (!resource?.id) return
409
+ if (!selectionMode) setSelectionMode(true)
410
+ const { nextSelectedIds, nextAnchorId } = applyResourceSelectionGesture({
411
+ selectedIds: batchSelectedIds,
412
+ orderedIds: orderedResourceIds,
413
+ targetId: resource.id,
414
+ event: { metaKey: true },
415
+ anchorId: selectionAnchorId,
416
+ })
417
+ setBatchSelectedIds(nextSelectedIds)
418
+ setSelectionAnchorId(nextAnchorId)
419
+ clearSelectedResourceId()
420
+ }, [
421
+ selectionMode,
422
+ batchSelectedIds,
423
+ orderedResourceIds,
424
+ selectionAnchorId,
425
+ clearSelectedResourceId,
426
+ ])
427
+
428
+ const handleBatchDownload = useCallback(() => {
429
+ if (selectedDownloadableResources.length === 0) return
430
+ triggerResourceDownloads(selectedDownloadableResources).catch((error) => {
431
+ console.error('[storage] batch download failed', error)
432
+ })
433
+ }, [selectedDownloadableResources])
434
+
435
+ const handleBatchRemoveConfirm = useCallback(async () => {
436
+ const resources = selectedBatchResources
437
+ setOverlay(Overlays.None)
438
+ try {
439
+ for (const resource of resources) {
440
+ await removeResource(sdk, resource.id, resource.location || activePath)
441
+ }
442
+ } catch (error) {
443
+ console.error('[storage] batch remove failed', error)
444
+ } finally {
445
+ exitSelectionMode()
446
+ }
447
+ }, [selectedBatchResources, sdk, activePath, exitSelectionMode])
448
+
449
+ const selectionCount = batchSelectedIds.size
450
+ const selectionLabel = selectionCount === 1
451
+ ? t('storage.resources.selectedOne')
452
+ : t('storage.resources.selectedMany').replace('{count}', String(selectionCount))
453
+ const showSelectionControls = selectionMode
289
454
  return (
290
455
  <>
291
456
  <style>
@@ -346,6 +511,20 @@ export const ResourcesPage = () => {
346
511
  </Breadcrumbs>
347
512
 
348
513
  <View layout="row" gap="xs" alignItems="center" style={{ flexShrink: 0 }}>
514
+ <Button
515
+ prefix="check-r"
516
+ variant="command"
517
+ aria-label={t('storage.resources.selectMode')}
518
+ aria-pressed={selectionMode}
519
+ label={selectionMode ? 'storage.resources.selectModeActive' : 'storage.resources.selectMode'}
520
+ onClick={toggleSelectionMode}
521
+ style={{
522
+ height: '32px',
523
+ ...(selectionMode
524
+ ? { background: 'var(--background-active)', color: 'var(--foreground-active, var(--foreground))' }
525
+ : {}),
526
+ }}
527
+ />
349
528
  <Dropdown
350
529
  trigger={(
351
530
  <Button
@@ -395,6 +574,53 @@ export const ResourcesPage = () => {
395
574
 
396
575
  </View.Item>
397
576
 
577
+ {selectionMode && (
578
+ <View.Item
579
+ data-surface="primary"
580
+ layout="row"
581
+ style={{
582
+ alignItems: 'center',
583
+ justifyContent: 'space-between',
584
+ padding: 'var(--space-xs) var(--space-m)',
585
+ gap: 'var(--space-m)',
586
+ minHeight: '40px',
587
+ flexShrink: 0,
588
+ borderBottom: '1px solid var(--separator-primary)',
589
+ }}
590
+ >
591
+ <Text variant="small">
592
+ {selectionCount > 0 ? selectionLabel : t('storage.resources.selectModeHint')}
593
+ </Text>
594
+ <View layout="row" gap="xs" alignItems="center" style={{ flexShrink: 0 }}>
595
+ <Button
596
+ prefix="software-download"
597
+ variant="command"
598
+ disabled={selectedDownloadableResources.length === 0}
599
+ onClick={handleBatchDownload}
600
+ style={{ height: '32px' }}
601
+ >
602
+ {t('storage.resources.downloadSelected')}
603
+ </Button>
604
+ <Button
605
+ prefix="trash-empty"
606
+ variant="command-danger"
607
+ disabled={selectedBatchResources.length === 0}
608
+ onClick={() => setOverlay(Overlays.RemoveBatch)}
609
+ style={{ height: '32px' }}
610
+ >
611
+ {t('storage.resources.removeSelected')}
612
+ </Button>
613
+ <Button
614
+ variant="command"
615
+ onClick={exitSelectionMode}
616
+ style={{ height: '32px' }}
617
+ >
618
+ {t('storage.resources.doneSelecting')}
619
+ </Button>
620
+ </View>
621
+ </View.Item>
622
+ )}
623
+
398
624
  <View.Item fill data-scrollbar="hide" style={{ overflowY: 'auto', minHeight: 0 }}>
399
625
  <DropZone onFilesDrop={onUploadFiles(activePath)}>
400
626
  <View style={{ minHeight: '100%' }} onContextMenu={handleDropZoneContextMenu}>
@@ -482,8 +708,26 @@ export const ResourcesPage = () => {
482
708
 
483
709
  <Switch.Case match={[ResourcesListStatus.Success]}>
484
710
  {viewMode === ViewMode.Grid
485
- ? <ResourceGrid resources={filterResources} inlineFolder={inlineFolder} />
486
- : <ResourceList resources={filterResources} inlineFolder={inlineFolder} />}
711
+ ? (
712
+ <ResourceGrid
713
+ resources={filterResources}
714
+ inlineFolder={inlineFolder}
715
+ selectedIds={highlightedIds}
716
+ showSelectionControls={showSelectionControls}
717
+ onClick={handleResourceActivate}
718
+ onToggleSelect={handleToggleSelect}
719
+ />
720
+ )
721
+ : (
722
+ <ResourceList
723
+ resources={filterResources}
724
+ inlineFolder={inlineFolder}
725
+ selectedIds={highlightedIds}
726
+ showSelectionControls={showSelectionControls}
727
+ onClick={handleResourceActivate}
728
+ onToggleSelect={handleToggleSelect}
729
+ />
730
+ )}
487
731
  </Switch.Case>
488
732
 
489
733
  </Switch>
@@ -525,6 +769,29 @@ export const ResourcesPage = () => {
525
769
  )
526
770
  }
527
771
 
772
+ {
773
+ overlay === Overlays.RemoveBatch && (
774
+ <Overlay isVisible={true} onClose={() => setOverlay(Overlays.None)}>
775
+ <View layout="off-center-s" style={{ height: '100%' }}>
776
+ <View data-region="content">
777
+ <View surface="primary" roundness="s">
778
+ <View surface="primary" inset="l" roundness="s">
779
+ <Guide
780
+ title={t('storage.resources.removeSelectedTitle')}
781
+ text={t('storage.resources.removeSelectedText').replace('{count}', String(selectionCount))}
782
+ actions={[
783
+ { label: t('storage.resources.cancel'), variant: 'command', onClick: () => setOverlay(Overlays.None) },
784
+ { label: t('storage.resources.removeSelected'), variant: 'command-danger', onClick: handleBatchRemoveConfirm },
785
+ ]}
786
+ />
787
+ </View>
788
+ </View>
789
+ </View>
790
+ </View>
791
+ </Overlay>
792
+ )
793
+ }
794
+
528
795
  {
529
796
  overlay === Overlays.MoveResource && (
530
797
  <Overlay isVisible={true} onClose={() => setOverlay(Overlays.None)}>
@@ -537,4 +804,3 @@ export const ResourcesPage = () => {
537
804
  </>
538
805
  )
539
806
  }
540
-
@@ -19,6 +19,18 @@
19
19
  "storage.resources.cancel": "Cancel",
20
20
  "storage.resources.remove": "Remove",
21
21
  "storage.resources.move": "Move",
22
+ "storage.resources.download": "Download",
23
+ "storage.resources.downloadSelected": "Download selected",
24
+ "storage.resources.removeSelected": "Remove selected",
25
+ "storage.resources.removeSelectedTitle": "Remove selected",
26
+ "storage.resources.removeSelectedText": "Are you sure you want to remove {count} selected items? Folders and their contents will be deleted.",
27
+ "storage.resources.selectMode": "Select",
28
+ "storage.resources.selectModeActive": "Selecting",
29
+ "storage.resources.selectModeHint": "Tap items to select them",
30
+ "storage.resources.doneSelecting": "Done",
31
+ "storage.resources.clearSelection": "Clear selection",
32
+ "storage.resources.selectedOne": "1 selected",
33
+ "storage.resources.selectedMany": "{count} selected",
22
34
  "storage.resources.contextRemove": "Remove",
23
35
  "storage.resources.layout": "Layout",
24
36
  "storage.resources.viewList": "List view",
@@ -1,6 +1,7 @@
1
1
  import { StorageClient } from '@ossy/platform'
2
2
  import { assertStorageKey } from '@ossy/platform/storage-keys'
3
3
  import { createLogger } from '@ossy/observability'
4
+ import { assertUploadAccessForStorageKey } from '@ossy/resources/server'
4
5
 
5
6
  const log = createLogger('local-storage')
6
7
 
@@ -44,17 +45,21 @@ export default async function handle (req, res) {
44
45
  return
45
46
  }
46
47
 
47
- // PUT — receive raw file bytes from CLI (same pattern as S3 presigned PUT)
48
+ // PUT — receive raw file bytes (same pattern as S3 presigned PUT, with session auth)
48
49
  if (req.method === 'PUT') {
49
50
  try {
51
+ await assertUploadAccessForStorageKey(key, req)
50
52
  const chunks = []
51
53
  for await (const chunk of req) chunks.push(chunk)
52
54
  const body = Buffer.concat(chunks)
53
55
  await StorageClient.save(key, body)
54
56
  res.status(200).end()
55
57
  } catch (err) {
56
- log.error('[local-storage] PUT failed', undefined, err)
57
- res.status(500).json({ error: err.message })
58
+ const status = err?.status ?? 500
59
+ if (status >= 500) {
60
+ log.error('[local-storage] PUT failed', undefined, err)
61
+ }
62
+ res.status(status).json({ error: err.message })
58
63
  }
59
64
  return
60
65
  }
@@ -19,6 +19,18 @@
19
19
  "storage.resources.cancel": "Avbryt",
20
20
  "storage.resources.remove": "Ta bort",
21
21
  "storage.resources.move": "Flytta",
22
+ "storage.resources.download": "Ladda ner",
23
+ "storage.resources.downloadSelected": "Ladda ner markerade",
24
+ "storage.resources.removeSelected": "Ta bort markerade",
25
+ "storage.resources.removeSelectedTitle": "Ta bort markerade",
26
+ "storage.resources.removeSelectedText": "Är du säker på att du vill ta bort {count} markerade objekt? Mappar och deras innehåll tas bort.",
27
+ "storage.resources.selectMode": "Markera",
28
+ "storage.resources.selectModeActive": "Markerar",
29
+ "storage.resources.selectModeHint": "Tryck på objekt för att markera dem",
30
+ "storage.resources.doneSelecting": "Klar",
31
+ "storage.resources.clearSelection": "Rensa markering",
32
+ "storage.resources.selectedOne": "1 markerad",
33
+ "storage.resources.selectedMany": "{count} markerade",
22
34
  "storage.resources.contextRemove": "Ta bort",
23
35
  "storage.resources.layout": "Layout",
24
36
  "storage.resources.viewList": "Listvy",