[go: nahoru, domu]

Skip to content

Commit

Permalink
feat(storage-resize-images): add parameter REGENERATE_TOKEN (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
jauntybrain committed Jan 31, 2024
1 parent 975ffdb commit a73901e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions _emulator/extensions/storage-resize-images.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ FAILED_IMAGES_PATH=failed
IMAGE_TYPE=webp
IS_ANIMATED=true
DO_BACKFILL=false
REGENERATE_TOKEN=true
SHARP_OPTIONS='{"fit":"cover", "position": "top", "animated": false}'
3 changes: 3 additions & 0 deletions storage-resize-images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ Leave this field empty if you do not want to store failed images in a separate d
* Backfill existing images: Should existing, unresized images in the Storage bucket be resized as well?


* Assign new access token: Should resized images have a new access token assigned to them, different from the original image?




**Cloud Functions:**
Expand Down
14 changes: 14 additions & 0 deletions storage-resize-images/extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ params:
- label: No
value: false

- param: REGENERATE_TOKEN
label: Assign new access token
description: >
Should resized images have a new access token assigned to them, different
from the original image?
type: select
required: false
default: true
options:
- label: Yes
value: true
- label: No
value: false

events:
- type: firebase.extensions.storage-resize-images.v1.onStart
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Object {
"location": "us-central1",
"makePublic": false,
"outputOptions": undefined,
"regenerateToken": false,
"resizedImagesPath": undefined,
"sharpOptions": "{}",
}
Expand Down
2 changes: 1 addition & 1 deletion storage-resize-images/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"ts-jest": "^24.1.0"
},
"private": true
}
}
1 change: 1 addition & 0 deletions storage-resize-images/functions/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default {
cacheControlHeader: process.env.CACHE_CONTROL_HEADER,
doBackfill: process.env.DO_BACKFILL === "true",
imageSizes: process.env.IMG_SIZES.split(","),
regenerateToken: process.env.REGENERATE_TOKEN == "true",
makePublic: process.env.MAKE_PUBLIC === "true",
resizedImagesPath: process.env.RESIZED_IMAGES_PATH,
includePathList: paramToArray(process.env.INCLUDE_PATH_LIST),
Expand Down
5 changes: 3 additions & 2 deletions storage-resize-images/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { shouldResize } from "./filters";
import * as events from "./events";
import { v4 as uuidv4 } from "uuid";
import { countNegativeTraversals } from "./util";
import { File } from "@google-cloud/storage";

sharp.cache(false);

Expand Down Expand Up @@ -60,8 +61,8 @@ const generateResizedImageHandler = async (
const parsedPath = path.parse(filePath);
const objectMetadata = object;

let localOriginalFile;
let remoteOriginalFile;
let localOriginalFile: string;
let remoteOriginalFile: File;
try {
localOriginalFile = path.join(os.tmpdir(), uuidv4());
const tempLocalDir = path.dirname(localOriginalFile);
Expand Down
5 changes: 4 additions & 1 deletion storage-resize-images/functions/src/resize-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ export const constructMetadata = (

// If the original image has a download token, add a
// new token to the image being resized #323
if (metadata.metadata.firebaseStorageDownloadTokens) {
if (
config.regenerateToken &&
metadata.metadata.firebaseStorageDownloadTokens
) {
metadata.metadata.firebaseStorageDownloadTokens = uuid();
}
return metadata;
Expand Down

0 comments on commit a73901e

Please sign in to comment.