Skip to content

Commit

Permalink
画像送受信実験
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicup committed Dec 26, 2023
1 parent d3833fd commit fc49ee9
Show file tree
Hide file tree
Showing 8 changed files with 46,362 additions and 3,280 deletions.
48,089 changes: 45,016 additions & 3,073 deletions dist/beta/index.js

Large diffs are not rendered by default.

272 changes: 168 additions & 104 deletions dist/query/index.js

Large diffs are not rendered by default.

270 changes: 167 additions & 103 deletions dist/track/index.js

Large diffs are not rendered by default.

959 changes: 959 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/aws-lambda": "^8.10.97",
"@types/totp-generator": "^0.0.8",
"@types/webpack": "^5.28.0",
"jimp": "^0.22.10",
"nodemon": "^2.0.16",
"terser-webpack-plugin": "^5.3.7",
"totp-generator": "^0.0.14",
Expand Down
8 changes: 8 additions & 0 deletions src/handlers/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {APIGatewayProxyCallbackV2, APIGatewayProxyEventV2, APIGatewayProxyResult
import pandaToolsTracker from "./beta/pandaToolsTracker";
import {debug} from "./beta/lib/env";
import pandaToolsTotp from "./beta/pandaToolsTotp";
import pandaToolsImageLoader from "./beta/pandaToolsImageLoader";
import pandaToolsImagePanel from "./beta/pandaToolsImagePanel";

export async function handler(event: APIGatewayProxyEventV2, context: Context, callback: APIGatewayProxyCallbackV2)
: Promise<APIGatewayProxyResultV2> {
Expand All @@ -19,5 +21,11 @@ export async function handler(event: APIGatewayProxyEventV2, context: Context, c
if ('cmd' in data && data.cmd === 'totp') {
return pandaToolsTotp(event, data)
}
if ('cmd' in data && data.cmd === 'imageLoader') {
return pandaToolsImageLoader(event, data)
}
if ('cmd' in data && data.cmd === 'imagePanel') {
return pandaToolsImagePanel(event, data)
}
return await pandaToolsTracker(event, data)
}
9 changes: 9 additions & 0 deletions src/handlers/beta/pandaToolsImageLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {APIGatewayProxyEventV2} from "aws-lambda";
import {callExternalResponse} from "./lib/env";

export default function pandaToolsImageLoader(event: APIGatewayProxyEventV2, data: any) {

const url = data.arg

return callExternalResponse(200, '');
}
34 changes: 34 additions & 0 deletions src/handlers/beta/pandaToolsImagePanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {APIGatewayProxyEventV2} from "aws-lambda";
import {callExternalResponse} from "./lib/env";
import Jimp from "jimp";

export default async function pandaToolsImagePanel(event: APIGatewayProxyEventV2, data: any) {

const arg = data.arg //{url: argUrl, x: pos.x, y: pos.y},

const arr = new Uint8Array(22*22*3/2)
const arrSet = (uint8:number, i:number) => {
const v = uint8 / 255 * 15
if (i%2) {
arr[i/2] |= v
} else {
arr[i/2] |= v<<4
}
}

const image = await Jimp.read('https://assets.st-note.com/production/uploads/images/86872191/profile_9fe8e505a6b16e6b1c38b047f66485dd.png?width=104&height=104&dpr=2&crop=1:1,smart');
image.resize(22,22).scan(0, 0, 22, 22, function (x, y, i) {
// x, y is the position of this pixel on the image
// idx is the position start position of this rgba tuple in the bitmap Buffer
// this is the image
const r = this.bitmap.data[i]
const g = this.bitmap.data[i + 1]
const b = this.bitmap.data[i + 2]
const a = this.bitmap.data[i + 3]
arrSet(r, i)
arrSet(g, i+1)
arrSet(b, i+2)
});
const b64 = Buffer.from(arr).toString("base64");
return callExternalResponse(200, b64);
}

0 comments on commit fc49ee9

Please sign in to comment.