Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
fix(user): add random ID to prevent caching
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Dec 11, 2022
1 parent 8f6916e commit 116ae9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions routes/api/user/log_in/image.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OptionalMiddleware } from "!/types/independent"
import { IMAGE_FILE_IDS, IMAGE_FILE_COUNT, DRIVE_LINK } from "!/constants/image_file_ids"

import Policy from "!/bases/policy"
import digest from "$!/helpers/digest"
import Validation from "!/bases/validation"
import specializePath from "$/helpers/specialize_path"
import Controller from "!/bases/controller-likes/controller"
Expand All @@ -21,11 +22,14 @@ export default class extends Controller {
get middlewares(): OptionalMiddleware[] {
return [
...super.middlewares,
new DynamicGatedRedirector(() => Promise.resolve({
new DynamicGatedRedirector(() => digest(
Buffer.from(String(Math.random()))
).then(randomID => ({
"location": specializePath(DRIVE_LINK, {
"id": IMAGE_FILE_IDS[Math.floor(Math.random() * IMAGE_FILE_COUNT)]
"id": IMAGE_FILE_IDS[Math.floor(Math.random() * IMAGE_FILE_COUNT)],
randomID
})
}))
})))
]
}

Expand Down
2 changes: 1 addition & 1 deletion server/constants/image_file_ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,4 @@ export const IMAGE_FILE_IDS = [

export const IMAGE_FILE_COUNT = IMAGE_FILE_IDS.length

export const DRIVE_LINK = "https://drive.google.com/uc?id=:id"
export const DRIVE_LINK = "https://drive.google.com/uc?id=:id&rand=:randomID"

0 comments on commit 116ae9f

Please sign in to comment.