@ossy/resources 1.11.7 → 1.12.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.
Files changed (69) hide show
  1. package/package.json +10 -4
  2. package/src/AudioResource.jsx +4 -2
  3. package/src/CreateDirectory.jsx +14 -13
  4. package/src/CreateDocument.jsx +7 -5
  5. package/src/Definition.js +2 -8
  6. package/src/DocumentEdit.jsx +9 -6
  7. package/src/DocumentView.jsx +8 -4
  8. package/src/GenericResourceCard.jsx +4 -2
  9. package/src/GenericResourceDetail.jsx +9 -4
  10. package/src/GenericResourceForm.jsx +14 -7
  11. package/src/ImageResource.jsx +4 -2
  12. package/src/PDFResource.jsx +4 -2
  13. package/src/ResourceContentPage.jsx +4 -2
  14. package/src/ResourceDescription.jsx +4 -3
  15. package/src/ResourceDetails.jsx +9 -4
  16. package/src/ResourceDialogMove.jsx +4 -3
  17. package/src/ResourceFactory.jsx +6 -3
  18. package/src/ResourceGenericView.jsx +4 -2
  19. package/src/ResourceList.jsx +4 -2
  20. package/src/ResourcePanel.jsx +9 -12
  21. package/src/ResourceTags.jsx +4 -3
  22. package/src/ResourcesPage.jsx +8 -6
  23. package/src/UploadResources.jsx +9 -11
  24. package/src/VideoResource.jsx +4 -2
  25. package/src/create-page-view.action.js +1 -38
  26. package/src/create-page-view.task.js +38 -0
  27. package/src/create.action.js +1 -98
  28. package/src/create.task.js +100 -0
  29. package/src/delete.action.js +1 -31
  30. package/src/delete.task.js +31 -0
  31. package/src/en.translations.json +48 -0
  32. package/src/get-page-view-stats.action.js +1 -65
  33. package/src/get-page-view-stats.task.js +64 -0
  34. package/src/get.action.js +1 -14
  35. package/src/get.task.js +14 -0
  36. package/src/index.js +13 -4
  37. package/src/list.action.js +1 -19
  38. package/src/list.task.js +20 -0
  39. package/src/resource-create.page.jsx +7 -5
  40. package/src/resource-detail.page.jsx +0 -2
  41. package/src/resource.helpers.js +83 -0
  42. package/src/resources.action-media.js +18 -0
  43. package/src/resources.attach-media-urls.js +1 -1
  44. package/src/resources.events.js +1 -0
  45. package/src/resources.spec.js +54 -55
  46. package/src/search.action.js +1 -19
  47. package/src/search.task.js +20 -0
  48. package/src/server.js +4 -0
  49. package/src/sv.translations.json +48 -0
  50. package/src/update-access.action.js +1 -20
  51. package/src/update-access.task.js +22 -0
  52. package/src/update-content.action.js +1 -39
  53. package/src/update-content.task.js +41 -0
  54. package/src/update-location.action.js +1 -18
  55. package/src/update-location.task.js +20 -0
  56. package/src/update-name.action.js +1 -18
  57. package/src/update-name.task.js +20 -0
  58. package/src/upload-named-version.action.js +1 -42
  59. package/src/upload-named-version.task.js +46 -0
  60. package/src/item-access.api.js +0 -34
  61. package/src/item-content.api.js +0 -35
  62. package/src/item-location.api.js +0 -34
  63. package/src/item-name.api.js +0 -34
  64. package/src/item-version.api.js +0 -48
  65. package/src/item.api.js +0 -58
  66. package/src/list.api.js +0 -43
  67. package/src/page-views-stats.api.js +0 -23
  68. package/src/page-views.api.js +0 -23
  69. package/src/search.api.js +0 -27
@@ -1,18 +1 @@
1
- import { Aggregate } from '@ossy/event-store'
2
- import { Resource, ResourcesEvents } from '@ossy/resources'
3
-
4
- export const id = 'resources/update-location'
5
- export const access = 'workspace'
6
-
7
- export async function run({ payload, req }) {
8
- const createdBy = payload?.userId ?? req?.userId
9
- const resourceId = payload?.resourceId ?? req?.params?.resourceId
10
- const location = payload?.target ?? payload?.location
11
-
12
- if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
13
- if (!location) throw Object.assign(new Error('target location is required'), { status: 400 })
14
-
15
- return Aggregate.Of(Resource, resourceId)
16
- .then(Aggregate.Add(ResourcesEvents.LocationUpdated({ createdBy, location })))
17
- .then(Aggregate.View())
18
- }
1
+ export const metadata = { id: 'resources/update-location', access: 'workspace' }
@@ -0,0 +1,20 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { Resource } from './resource.aggregate.js'
3
+ import { ResourcesEvents } from './resources.events.js'
4
+ import { mediaContextFromRun, withResourceMedia } from './resources.action-media.js'
5
+
6
+ export const metadata = { id: 'resources/update-location' }
7
+
8
+ export async function run({ payload, req }) {
9
+ const createdBy = payload?.userId ?? req?.userId
10
+ const resourceId = payload?.resourceId ?? req?.params?.resourceId
11
+ const location = payload?.target ?? payload?.location
12
+
13
+ if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
14
+ if (!location) throw Object.assign(new Error('target location is required'), { status: 400 })
15
+
16
+ const resource = await Aggregate.Of(Resource, resourceId)
17
+ .then(Aggregate.Add(ResourcesEvents.LocationUpdated({ createdBy, location })))
18
+ .then(Aggregate.View())
19
+ return withResourceMedia(resource, mediaContextFromRun({ payload, req }))
20
+ }
@@ -1,18 +1 @@
1
- import { Aggregate } from '@ossy/event-store'
2
- import { Resource, ResourcesEvents } from '@ossy/resources'
3
-
4
- export const id = 'resources/update-name'
5
- export const access = 'workspace'
6
-
7
- export async function run({ payload, req }) {
8
- const createdBy = payload?.userId ?? req?.userId
9
- const resourceId = payload?.resourceId ?? req?.params?.resourceId
10
- const name = payload?.name
11
-
12
- if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
13
- if (!name) throw Object.assign(new Error('name is required'), { status: 400 })
14
-
15
- return Aggregate.Of(Resource, resourceId)
16
- .then(Aggregate.Add(ResourcesEvents.NameUpdated({ createdBy, name })))
17
- .then(Aggregate.View())
18
- }
1
+ export const metadata = { id: 'resources/update-name', access: 'workspace' }
@@ -0,0 +1,20 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { Resource } from './resource.aggregate.js'
3
+ import { ResourcesEvents } from './resources.events.js'
4
+ import { mediaContextFromRun, withResourceMedia } from './resources.action-media.js'
5
+
6
+ export const metadata = { id: 'resources/update-name' }
7
+
8
+ export async function run({ payload, req }) {
9
+ const createdBy = payload?.userId ?? req?.userId
10
+ const resourceId = payload?.resourceId ?? req?.params?.resourceId
11
+ const name = payload?.name
12
+
13
+ if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
14
+ if (!name) throw Object.assign(new Error('name is required'), { status: 400 })
15
+
16
+ const resource = await Aggregate.Of(Resource, resourceId)
17
+ .then(Aggregate.Add(ResourcesEvents.NameUpdated({ createdBy, name })))
18
+ .then(Aggregate.View())
19
+ return withResourceMedia(resource, mediaContextFromRun({ payload, req }))
20
+ }
@@ -1,42 +1 @@
1
- import { Aggregate } from '@ossy/event-store'
2
- import { Resource, ResourcesEvents } from '@ossy/resources'
3
- import { Workspace } from '@ossy/workspaces'
4
-
5
- export const id = 'resources/upload-named-version'
6
- export const access = 'workspace'
7
-
8
- export async function run({ payload, integrations, req }) {
9
- const createdBy = payload?.userId ?? req?.userId
10
- const workspaceId = payload?.workspaceId ?? req?.workspaceId
11
- const resourceId = payload?.resourceId ?? req?.params?.resourceId
12
- const namedVersion = payload?.namedVersion ?? req?.params?.namedVersion
13
- const type = payload?.type
14
- const size = payload?.size
15
-
16
- if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
17
- if (!namedVersion) throw Object.assign(new Error('namedVersion is required'), { status: 400 })
18
-
19
- const workspace = await Aggregate.Of(Workspace, workspaceId).then(Aggregate.View())
20
-
21
- const event = ResourcesEvents.NamedVersionUploaded({
22
- createdBy,
23
- namedVersion,
24
- Key: `media/${workspace.id}/${resourceId}/${namedVersion}.${type.replace('image/', '')}`,
25
- ContentLength: size,
26
- ContentType: type,
27
- })
28
-
29
- const storageClient = integrations?.get?.('storage')
30
- const uploadHeaders = {
31
- ContentLength: event.payload.ContentLength,
32
- ContentType: event.payload.ContentType,
33
- Key: event.payload.Key,
34
- }
35
- const uploadUrl = storageClient ? await storageClient.createUploadUrl(uploadHeaders) : null
36
- const resource = await Aggregate.Of(Resource, resourceId)
37
- .then(Aggregate.Add(event))
38
- .then(Aggregate.View())
39
- return uploadUrl
40
- ? { ...resource, content: { ...resource.content, uploadUrl } }
41
- : resource
42
- }
1
+ export const metadata = { id: 'resources/upload-named-version', access: 'workspace' }
@@ -0,0 +1,46 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { Resource } from './resource.aggregate.js'
3
+ import { ResourcesEvents } from './resources.events.js'
4
+ import { Workspace } from '@ossy/workspaces/server'
5
+ import { mediaContextFromRun, withResourceMedia } from './resources.action-media.js'
6
+
7
+ export const metadata = { id: 'resources/upload-named-version' }
8
+
9
+ // TODO: remove named version concept
10
+
11
+ export async function run({ payload, integrations, req }) {
12
+ const createdBy = payload?.userId ?? req?.userId
13
+ const workspaceId = payload?.workspaceId ?? req?.workspaceId
14
+ const resourceId = payload?.resourceId ?? req?.params?.resourceId
15
+ const namedVersion = payload?.namedVersion ?? req?.params?.namedVersion
16
+ const type = payload?.type
17
+ const size = payload?.size
18
+
19
+ if (!resourceId) throw Object.assign(new Error('resourceId is required'), { status: 400 })
20
+ if (!namedVersion) throw Object.assign(new Error('namedVersion is required'), { status: 400 })
21
+
22
+ const workspace = await Aggregate.Of(Workspace, workspaceId).then(Aggregate.View())
23
+
24
+ const event = ResourcesEvents.NamedVersionUploaded({
25
+ createdBy,
26
+ namedVersion,
27
+ Key: `media/${workspace.id}/${resourceId}/${namedVersion}.${type.replace('image/', '')}`,
28
+ ContentLength: size,
29
+ ContentType: type,
30
+ })
31
+
32
+ const storageClient = integrations?.get?.('storage')
33
+ const uploadHeaders = {
34
+ ContentLength: event.payload.ContentLength,
35
+ ContentType: event.payload.ContentType,
36
+ Key: event.payload.Key,
37
+ }
38
+ const uploadUrl = storageClient ? await storageClient.createUploadUrl(uploadHeaders) : null
39
+ const resource = await Aggregate.Of(Resource, resourceId)
40
+ .then(Aggregate.Add(event))
41
+ .then(Aggregate.View())
42
+ const withUpload = uploadUrl
43
+ ? { ...resource, content: { ...resource.content, uploadUrl } }
44
+ : resource
45
+ return withResourceMedia(withUpload, mediaContextFromRun({ payload, req }))
46
+ }
@@ -1,34 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)\/access$/
5
-
6
- export const metadata = {
7
- id: 'resources.item.access',
8
- path: '/api/v0/resources/:resourceId/access',
9
- }
10
-
11
- export default async function handle(req, res) {
12
- if (req.method !== 'PUT') {
13
- res.setHeader('Allow', 'PUT')
14
- res.status(405).json({ error: 'Method Not Allowed' })
15
- return
16
- }
17
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
18
- const m = pathname.match(pathRe)
19
- if (!m) {
20
- res.status(404).json('')
21
- return
22
- }
23
- const resourceId = decodeURIComponent(m[1])
24
- try {
25
- const resource = await ActionService.invoke('resources/update-access', {
26
- payload: { resourceId, access: req.body?.access, userId: req.userId },
27
- req,
28
- })
29
- const withUrls = await attachResourceMediaUrls(resource, { userId: req.userId, workspaceId: req.workspaceId })
30
- res.json(withUrls)
31
- } catch (err) {
32
- res.status(err?.status ?? 500).json({ error: err?.message })
33
- }
34
- }
@@ -1,35 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)\/content$/
5
-
6
- export const metadata = {
7
- id: 'resources.item.content',
8
- path: '/api/v0/resources/:resourceId/content',
9
- }
10
-
11
- export default async function handle(req, res) {
12
- if (req.method !== 'PUT') {
13
- res.setHeader('Allow', 'PUT')
14
- res.status(405).json({ error: 'Method Not Allowed' })
15
- return
16
- }
17
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
18
- const m = pathname.match(pathRe)
19
- if (!m) {
20
- res.status(404).json('')
21
- return
22
- }
23
- const resourceId = decodeURIComponent(m[1])
24
- try {
25
- const resource = await ActionService.invoke('resources/update-content', {
26
- payload: { resourceId, content: req.body?.content, userId: req.userId, workspaceId: req.workspaceId },
27
- req,
28
- })
29
- if (resource === null || resource === undefined) return
30
- const withUrls = await attachResourceMediaUrls(resource, { userId: req.userId, workspaceId: req.workspaceId })
31
- res.json(withUrls)
32
- } catch (err) {
33
- res.status(err?.status ?? 400).json({ type: err?.type, message: err?.message })
34
- }
35
- }
@@ -1,34 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)\/location$/
5
-
6
- export const metadata = {
7
- id: 'resources.item.location',
8
- path: '/api/v0/resources/:resourceId/location',
9
- }
10
-
11
- export default async function handle(req, res) {
12
- if (req.method !== 'PUT') {
13
- res.setHeader('Allow', 'PUT')
14
- res.status(405).json({ error: 'Method Not Allowed' })
15
- return
16
- }
17
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
18
- const m = pathname.match(pathRe)
19
- if (!m) {
20
- res.status(404).json('')
21
- return
22
- }
23
- const resourceId = decodeURIComponent(m[1])
24
- try {
25
- const resource = await ActionService.invoke('resources/update-location', {
26
- payload: { resourceId, target: req.body?.target, userId: req.userId },
27
- req,
28
- })
29
- const withUrls = await attachResourceMediaUrls(resource, { userId: req.userId, workspaceId: req.workspaceId })
30
- res.json(withUrls)
31
- } catch (err) {
32
- res.status(err?.status ?? 500).json({ error: err?.message })
33
- }
34
- }
@@ -1,34 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)\/name$/
5
-
6
- export const metadata = {
7
- id: 'resources.item.name',
8
- path: '/api/v0/resources/:resourceId/name',
9
- }
10
-
11
- export default async function handle(req, res) {
12
- if (req.method !== 'PUT') {
13
- res.setHeader('Allow', 'PUT')
14
- res.status(405).json({ error: 'Method Not Allowed' })
15
- return
16
- }
17
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
18
- const m = pathname.match(pathRe)
19
- if (!m) {
20
- res.status(404).json('')
21
- return
22
- }
23
- const resourceId = decodeURIComponent(m[1])
24
- try {
25
- const resource = await ActionService.invoke('resources/update-name', {
26
- payload: { resourceId, name: req.body?.name, userId: req.userId },
27
- req,
28
- })
29
- const withUrls = await attachResourceMediaUrls(resource, { userId: req.userId, workspaceId: req.workspaceId })
30
- res.json(withUrls)
31
- } catch (err) {
32
- res.status(err?.status ?? 500).json({ error: err?.message })
33
- }
34
- }
@@ -1,48 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)\/([^/]+)$/
5
- const reservedSecond = new Set(['name', 'location', 'content', 'access'])
6
-
7
- export const metadata = {
8
- id: 'resources.item.version',
9
- path: '/api/v0/resources/:resourceId/:namedVersion',
10
- }
11
-
12
- export default async function handle(req, res) {
13
- if (req.method !== 'PUT') {
14
- res.setHeader('Allow', 'PUT')
15
- res.status(405).json({ error: 'Method Not Allowed' })
16
- return
17
- }
18
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
19
- const m = pathname.match(pathRe)
20
- if (!m) {
21
- res.status(404).json('')
22
- return
23
- }
24
- const namedVersion = decodeURIComponent(m[2])
25
- if (reservedSecond.has(namedVersion)) {
26
- res.status(404).json('')
27
- return
28
- }
29
- const resourceId = decodeURIComponent(m[1])
30
- try {
31
- const resource = await ActionService.invoke('resources/upload-named-version', {
32
- payload: {
33
- resourceId,
34
- namedVersion,
35
- type: req.body?.type,
36
- size: req.body?.size,
37
- userId: req.userId,
38
- workspaceId: req.workspaceId,
39
- },
40
- integrations: req.integrations,
41
- req,
42
- })
43
- const withUrls = await attachResourceMediaUrls(resource, { userId: req.userId, workspaceId: req.workspaceId })
44
- res.json(withUrls)
45
- } catch (err) {
46
- res.status(err?.status ?? 400).json({ error: err?.message })
47
- }
48
- }
package/src/item.api.js DELETED
@@ -1,58 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- const pathRe = /^\/api\/v0\/resources\/([^/]+)$/
5
-
6
- export const metadata = {
7
- id: 'resources.item',
8
- path: '/api/v0/resources/:resourceId',
9
- }
10
-
11
- function mediaContext(req) {
12
- return { userId: req.userId, workspaceId: req.workspaceId }
13
- }
14
-
15
- export default async function handle(req, res) {
16
- const pathname = (req.path || new URL(req.originalUrl, 'http://localhost').pathname).replace(/\/+$/, '')
17
- const m = pathname.match(pathRe)
18
- if (!m) {
19
- res.status(404).json('')
20
- return
21
- }
22
- const segment = decodeURIComponent(m[1])
23
- const reserved = new Set(['search', 'page-views'])
24
- if (reserved.has(segment)) {
25
- res.status(404).json('')
26
- return
27
- }
28
-
29
- req.params = { ...req.params, resourceId: segment }
30
-
31
- if (req.method === 'GET') {
32
- try {
33
- const resource = await ActionService.invoke('resources/get', {
34
- payload: { resourceId: segment },
35
- req,
36
- })
37
- const withUrls = await attachResourceMediaUrls(resource, mediaContext(req))
38
- res.json(withUrls)
39
- } catch (err) {
40
- res.status(err?.status ?? 500).json({ error: err?.message })
41
- }
42
- return
43
- }
44
- if (req.method === 'DELETE') {
45
- try {
46
- await ActionService.invoke('resources/delete', {
47
- payload: { resourceId: segment, userId: req.userId },
48
- req,
49
- })
50
- res.status(204).end()
51
- } catch (err) {
52
- res.status(err?.status ?? 500).json({ error: err?.message })
53
- }
54
- return
55
- }
56
- res.setHeader('Allow', 'GET, DELETE')
57
- res.status(405).json({ error: 'Method Not Allowed' })
58
- }
package/src/list.api.js DELETED
@@ -1,43 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- export const metadata = {
5
- id: 'resources.list',
6
- path: '/api/v0/resources',
7
- }
8
-
9
- function mediaContext(req) {
10
- return { userId: req.userId, workspaceId: req.workspaceId }
11
- }
12
-
13
- export default async function handle(req, res) {
14
- if (req.method === 'POST') {
15
- try {
16
- const resource = await ActionService.invoke('resources/create', {
17
- payload: { ...req.body, userId: req.userId, workspaceId: req.workspaceId },
18
- integrations: req.integrations,
19
- req,
20
- })
21
- const withUrls = await attachResourceMediaUrls(resource, mediaContext(req))
22
- res.json(withUrls)
23
- } catch (err) {
24
- res.status(err?.status ?? 500).json({ error: err?.message })
25
- }
26
- return
27
- }
28
- if (req.method === 'GET') {
29
- try {
30
- const resources = await ActionService.invoke('resources/list', {
31
- payload: { query: req.query, workspaceId: req.workspaceId, userId: req.userId, user: req.user },
32
- req,
33
- })
34
- const withUrls = await Promise.all(resources.map(r => attachResourceMediaUrls(r, mediaContext(req))))
35
- res.json(withUrls)
36
- } catch (err) {
37
- res.status(err?.status ?? 500).json({ error: err?.message })
38
- }
39
- return
40
- }
41
- res.setHeader('Allow', 'GET, POST')
42
- res.status(405).json({ error: 'Method Not Allowed' })
43
- }
@@ -1,23 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
-
3
- export const metadata = {
4
- id: 'resources.pageViews.stats',
5
- path: '/api/v0/resources/page-views/stats',
6
- }
7
-
8
- export default async function handle(req, res) {
9
- if (req.method !== 'GET') {
10
- res.setHeader('Allow', 'GET')
11
- res.status(405).json({ error: 'Method Not Allowed' })
12
- return
13
- }
14
- try {
15
- const result = await ActionService.invoke('resources/get-page-view-stats', {
16
- payload: { workspaceId: req.workspaceId, from: req.query?.from, to: req.query?.to, limit: req.query?.limit },
17
- req,
18
- })
19
- res.json(result)
20
- } catch (err) {
21
- res.status(err?.status ?? 500).json({ error: err?.message })
22
- }
23
- }
@@ -1,23 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
-
3
- export const metadata = {
4
- id: 'resources.pageViews',
5
- path: '/api/v0/resources/page-views',
6
- }
7
-
8
- export default async function handle(req, res) {
9
- if (req.method !== 'POST') {
10
- res.setHeader('Allow', 'POST')
11
- res.status(405).json({ error: 'Method Not Allowed' })
12
- return
13
- }
14
- try {
15
- const result = await ActionService.invoke('resources/create-page-view', {
16
- payload: { ...req.body, workspaceId: req.workspaceId, userId: req.userId },
17
- req,
18
- })
19
- res.status(201).json(result)
20
- } catch (err) {
21
- res.status(err?.status ?? 500).json({ error: err?.message })
22
- }
23
- }
package/src/search.api.js DELETED
@@ -1,27 +0,0 @@
1
- import { ActionService } from '@ossy/platform'
2
- import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
3
-
4
- export const metadata = {
5
- id: 'resources.search',
6
- path: '/api/v0/resources/search',
7
- }
8
-
9
- export default async function handle(req, res) {
10
- if (req.method !== 'POST') {
11
- res.setHeader('Allow', 'POST')
12
- res.status(405).json({ error: 'Method Not Allowed' })
13
- return
14
- }
15
- try {
16
- const resources = await ActionService.invoke('resources/search', {
17
- payload: { ...req.body, workspaceId: req.workspaceId, user: req.user },
18
- req,
19
- })
20
- const withUrls = await Promise.all(
21
- resources.map(r => attachResourceMediaUrls(r, { userId: req.userId, workspaceId: req.workspaceId }))
22
- )
23
- res.json(withUrls)
24
- } catch (err) {
25
- res.status(err?.status ?? 500).json({ error: err?.message })
26
- }
27
- }