-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1441 from tubone24/ogp
netlify blobを使って保存
- Loading branch information
Showing
4 changed files
with
69 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import "@sentry/tracing"; | |
import { ProfilingIntegration } from "@sentry/profiling-node"; | ||
import * as opentype from "opentype.js"; | ||
import sharp from "sharp"; | ||
import { getStore } from "@netlify/blobs"; | ||
|
||
Sentry.init({ | ||
dsn: "https://[email protected]/4506916048732160", | ||
|
@@ -28,6 +29,23 @@ exports.handler = async (event, context) => { | |
const user = `by ` + (queryStringParameters.user?.toString() || "tubone24"); | ||
|
||
try { | ||
const ogp = getStore("ogp"); | ||
const ogpArrayBuf = await ogp.get(`${encodeURIComponent(title)}`, { | ||
type: "arrayBuffer", | ||
}); | ||
|
||
if (ogpArrayBuf !== null) { | ||
transaction.finish(); | ||
return { | ||
statusCode: 200, | ||
headers: { | ||
"Content-Type": "image/png", | ||
}, | ||
body: new Buffer(Buffer.from(ogpArrayBuf)).toString("base64"), | ||
isBase64Encoded: true, | ||
}; | ||
} | ||
|
||
// SVGを生成 | ||
const svg = ` | ||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${1200}" height="${630}"> | ||
|
@@ -90,6 +108,12 @@ exports.handler = async (event, context) => { | |
.png() | ||
.toBuffer(); | ||
|
||
const arrayBuf = new Uint8Array(buffer).buffer; | ||
|
||
await ogp.set(`${encodeURIComponent(title)}`, arrayBuf, { | ||
createdAt: new Date(), | ||
}); | ||
|
||
transaction.finish(); | ||
|
||
return { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"author": "tubone <[email protected]>", | ||
"dependencies": { | ||
"@loadable/component": "5.15.3", | ||
"@netlify/blobs": "7.0.1", | ||
"@popperjs/core": "2.11.8", | ||
"@raae/gatsby-remark-oembed": "0.3.3", | ||
"@sentry/browser": "7.31.1", | ||
|
@@ -140,8 +141,8 @@ | |
"devDependencies": { | ||
"@babel/core": "7.23.7", | ||
"@babel/eslint-parser": "7.23.3", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@babel/plugin-syntax-typescript": "7.23.3", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@cypress/code-coverage": "3.12.18", | ||
"@storybook/addon-a11y": "6.5.16", | ||
"@storybook/addon-actions": "6.5.16", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters