create-ampless 1.0.0-alpha.60 → 1.0.0-alpha.61
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.
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { util } from '@aws-appsync/utils'
|
|
2
|
+
|
|
3
|
+
// AppSync JS resolver: returns a single Media row by S3 key.
|
|
4
|
+
//
|
|
5
|
+
// Reads the Media table's `bySrc` GSI: PK = src. The src is the full
|
|
6
|
+
// S3 key (`public/media/...`) and is unique across the table (uploads
|
|
7
|
+
// use a timestamp-prefixed naming scheme), so this is an O(1) PK
|
|
8
|
+
// Query with `limit: 1` — no scan, no filter.
|
|
9
|
+
//
|
|
10
|
+
// Returns null when no row matches (orphan / legacy assets); the
|
|
11
|
+
// caller (the `/api/media/...` route handler) falls back to an
|
|
12
|
+
// Amplify SSR HEAD via `getProperties` in that case.
|
|
13
|
+
//
|
|
14
|
+
// Authorisation is enforced by AppSync (`allow.publicApiKey()` on
|
|
15
|
+
// the schema declaration). The resolver itself only encodes the
|
|
16
|
+
// partition condition.
|
|
17
|
+
export function request(ctx) {
|
|
18
|
+
const src = ctx.args.src
|
|
19
|
+
return {
|
|
20
|
+
operation: 'Query',
|
|
21
|
+
index: 'bySrc',
|
|
22
|
+
query: {
|
|
23
|
+
expression: '#src = :src',
|
|
24
|
+
expressionNames: { '#src': 'src' },
|
|
25
|
+
expressionValues: util.dynamodb.toMapValues({ ':src': src }),
|
|
26
|
+
},
|
|
27
|
+
limit: 1,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function response(ctx) {
|
|
32
|
+
if (ctx.error) util.error(ctx.error.message, ctx.error.type)
|
|
33
|
+
const items = ctx.result.items ?? []
|
|
34
|
+
if (items.length === 0) return null
|
|
35
|
+
const item = items[0]
|
|
36
|
+
// Project explicitly onto the PublicMedia shape — drop mediaId /
|
|
37
|
+
// delivery / anything else that might be added to the Media model
|
|
38
|
+
// later so guests never see fields they shouldn't.
|
|
39
|
+
return {
|
|
40
|
+
src: item.src,
|
|
41
|
+
size: item.size ?? null,
|
|
42
|
+
mimeType: item.mimeType ?? null,
|
|
43
|
+
metadata: item.metadata ?? null,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -20,8 +20,9 @@ import { customSchemaModels } from './resource.custom.js'
|
|
|
20
20
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
21
21
|
|
|
22
22
|
// Ampless's built-in models (Post / Page / Media / Taxonomy / PostTag /
|
|
23
|
-
// KvStore) plus the
|
|
24
|
-
// (listPublishedPosts / getPublishedPost / listPostsByTag
|
|
23
|
+
// KvStore) plus the public-read custom queries
|
|
24
|
+
// (listPublishedPosts / getPublishedPost / listPostsByTag /
|
|
25
|
+
// getMediaBySrc).
|
|
25
26
|
//
|
|
26
27
|
// Add project-specific models in `amplify/data/resource.custom.ts` —
|
|
27
28
|
// that file is never overwritten by `create-ampless upgrade`.
|
|
@@ -29,6 +30,7 @@ const resolverPaths = {
|
|
|
29
30
|
listPublishedPosts: resolve(__dirname, 'list-published-posts.js'),
|
|
30
31
|
getPublishedPost: resolve(__dirname, 'get-published-post.js'),
|
|
31
32
|
listPostsByTag: resolve(__dirname, 'list-posts-by-tag.js'),
|
|
33
|
+
getMediaBySrc: resolve(__dirname, 'get-media-by-src.js'),
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const schema = a
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"@tiptap/pm": "^3.23.6",
|
|
26
26
|
"@tiptap/react": "^3.23.6",
|
|
27
27
|
"@tiptap/starter-kit": "^3.23.6",
|
|
28
|
-
"@ampless/plugin-og-image": "^0.2.0-alpha.
|
|
29
|
-
"@ampless/plugin-rss": "^0.2.0-alpha.
|
|
30
|
-
"@ampless/plugin-seo": "^0.2.0-alpha.
|
|
31
|
-
"@ampless/plugin-webhook": "^0.2.0-alpha.
|
|
32
|
-
"@ampless/admin": "^1.0.0-alpha.
|
|
33
|
-
"@ampless/backend": "^1.0.0-alpha.
|
|
34
|
-
"@ampless/runtime": "^1.0.0-alpha.
|
|
28
|
+
"@ampless/plugin-og-image": "^0.2.0-alpha.16",
|
|
29
|
+
"@ampless/plugin-rss": "^0.2.0-alpha.16",
|
|
30
|
+
"@ampless/plugin-seo": "^0.2.0-alpha.16",
|
|
31
|
+
"@ampless/plugin-webhook": "^0.2.0-alpha.16",
|
|
32
|
+
"@ampless/admin": "^1.0.0-alpha.40",
|
|
33
|
+
"@ampless/backend": "^1.0.0-alpha.31",
|
|
34
|
+
"@ampless/runtime": "^1.0.0-alpha.22",
|
|
35
35
|
"@digital-go-jp/tailwind-theme-plugin": "^0.3.4",
|
|
36
|
-
"ampless": "^1.0.0-alpha.
|
|
36
|
+
"ampless": "^1.0.0-alpha.16",
|
|
37
37
|
"aws-amplify": "^6.17.0",
|
|
38
38
|
"class-variance-authority": "^0.7.1",
|
|
39
39
|
"clsx": "^2.1.1",
|