Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions kits/storage-resize-images/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions kits/storage-resize-images/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
"firebase-admin": "^13.2.0",
"firebase-functions": "7.3.2",
"genkit": "^1.2.0",
"mkdirp": "^3.0.1",
"p-queue": "^6.6.2",
"sharp": "^0.35.3",
"uuid": "^11.0.5"
"sharp": "^0.35.3"
}
}
7 changes: 3 additions & 4 deletions kits/storage-resize-images/src/file-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
* limitations under the License.
*/

import * as crypto from "node:crypto";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { Bucket, File } from "@google-cloud/storage";
import { mkdirp } from "mkdirp";
import { v4 as uuidv4 } from "uuid";
import type { ResolvedResizeImagesConfig } from "./export-config";
import * as logs from "./logs";
import { countNegativeTraversals, type StorageObjectMetadata } from "./util";
Expand All @@ -29,11 +28,11 @@ export async function downloadOriginalFile(
filePath: string,
verbose: boolean
): Promise<[string, File]> {
const localFile = path.join(os.tmpdir(), uuidv4());
const localFile = path.join(os.tmpdir(), crypto.randomUUID());
const tempLocalDir = path.dirname(localFile);

if (verbose) logs.tempDirectoryCreating(tempLocalDir);
await mkdirp(tempLocalDir);
await fs.promises.mkdir(tempLocalDir, { recursive: true });
if (verbose) logs.tempDirectoryCreated(tempLocalDir);

const remoteFile = bucket.file(filePath);
Expand Down
6 changes: 3 additions & 3 deletions kits/storage-resize-images/src/resize-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import * as crypto from "node:crypto";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { Bucket } from "@google-cloud/storage";
import sharp from "sharp";
import { v4 as uuidv4 } from "uuid";
import type { ResolvedResizeImagesConfig } from "./export-config";
import {
SUPPORTED_EXTENSIONS,
Expand Down Expand Up @@ -124,7 +124,7 @@ export const modifyImage = async ({
let modifiedFile: string | undefined;

try {
modifiedFile = path.join(os.tmpdir(), uuidv4());
modifiedFile = path.join(os.tmpdir(), crypto.randomUUID());
const metadata = constructMetadata(
modifiedFileName,
imageContentType,
Expand Down Expand Up @@ -204,7 +204,7 @@ export const constructMetadata = (
config.cacheControlHeader ?? objectMetadata.cacheControl;

if (config.regenerateToken && customMetadata.firebaseStorageDownloadTokens) {
customMetadata.firebaseStorageDownloadTokens = uuidv4();
customMetadata.firebaseStorageDownloadTokens = crypto.randomUUID();
}
return metadata;
};
Expand Down
6 changes: 3 additions & 3 deletions kits/storage-resize-images/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import * as crypto from "node:crypto";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { Bucket, FileMetadata } from "@google-cloud/storage";
import { logger } from "firebase-functions";
import sharp from "sharp";
import { v4 as uuidv4 } from "uuid";
import { SUPPORTED_CONTENT_TYPES, SUPPORTED_EXTENSIONS } from "./global";
import * as logs from "./logs";

Expand Down Expand Up @@ -105,7 +105,7 @@ export async function replaceWithConfiguredPlaceholder(
);

const placeholderFile = bucket.file(placeholderPath);
const tempPlaceholder = path.join(os.tmpdir(), uuidv4());
const tempPlaceholder = path.join(os.tmpdir(), crypto.randomUUID());

await placeholderFile.download({ destination: tempPlaceholder });

Expand All @@ -125,7 +125,7 @@ export async function replaceWithDefaultPlaceholder(
localFile: string
): Promise<void> {
const localPlaceholderFile = path.join(__dirname, "placeholder.png");
const tempPlaceholder = path.join(os.tmpdir(), uuidv4());
const tempPlaceholder = path.join(os.tmpdir(), crypto.randomUUID());
fs.copyFileSync(localPlaceholderFile, tempPlaceholder);
fs.unlinkSync(localFile);
fs.renameSync(tempPlaceholder, localFile);
Expand Down
Loading