-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to images instead of files again
- Loading branch information
1 parent
6c99aa9
commit c7c0fe8
Showing
92 changed files
with
534 additions
and
496 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
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
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
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
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
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
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
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
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
28 changes: 0 additions & 28 deletions
28
exercises/02.relationships/02.problem.one-to-one/app/routes/resources+/files.$fileId.tsx
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
exercises/02.relationships/02.problem.one-to-one/app/routes/resources+/images.$imageId.tsx
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Response, type DataFunctionArgs } from '@remix-run/node' | ||
import fs from 'node:fs' | ||
import { PassThrough } from 'node:stream' | ||
import { db } from '~/utils/db.server.ts' | ||
import { invariantResponse } from '~/utils/misc.ts' | ||
|
||
export async function loader({ params }: DataFunctionArgs) { | ||
invariantResponse(params.imageId, 'Invalid image ID') | ||
const image = db.image.findFirst({ | ||
where: { id: { equals: params.imageId } }, | ||
}) | ||
invariantResponse(image, 'Image not found', { status: 404 }) | ||
|
||
const { filepath, contentType } = image | ||
const fileStat = await fs.promises.stat(filepath) | ||
const body = new PassThrough() | ||
const stream = fs.createReadStream(filepath) | ||
stream.on('open', () => stream.pipe(body)) | ||
stream.on('error', err => body.end(err)) | ||
stream.on('end', () => body.end()) | ||
return new Response(body, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': contentType, | ||
'Content-Length': fileStat.size.toString(), | ||
'Content-Disposition': `inline; filename="${params.imageId}"`, | ||
'Cache-Control': 'public, max-age=31536000, immutable', | ||
}, | ||
}) | ||
} |
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
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
28 changes: 0 additions & 28 deletions
28
exercises/02.relationships/02.solution.one-to-one/app/routes/resources+/files.$fileId.tsx
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
exercises/02.relationships/02.solution.one-to-one/app/routes/resources+/images.$imageId.tsx
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Response, type DataFunctionArgs } from '@remix-run/node' | ||
import fs from 'node:fs' | ||
import { PassThrough } from 'node:stream' | ||
import { db } from '~/utils/db.server.ts' | ||
import { invariantResponse } from '~/utils/misc.ts' | ||
|
||
export async function loader({ params }: DataFunctionArgs) { | ||
invariantResponse(params.imageId, 'Invalid image ID') | ||
const image = db.image.findFirst({ | ||
where: { id: { equals: params.imageId } }, | ||
}) | ||
invariantResponse(image, 'Image not found', { status: 404 }) | ||
|
||
const { filepath, contentType } = image | ||
const fileStat = await fs.promises.stat(filepath) | ||
const body = new PassThrough() | ||
const stream = fs.createReadStream(filepath) | ||
stream.on('open', () => stream.pipe(body)) | ||
stream.on('error', err => body.end(err)) | ||
stream.on('end', () => body.end()) | ||
return new Response(body, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': contentType, | ||
'Content-Length': fileStat.size.toString(), | ||
'Content-Disposition': `inline; filename="${params.imageId}"`, | ||
'Cache-Control': 'public, max-age=31536000, immutable', | ||
}, | ||
}) | ||
} |
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
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
Oops, something went wrong.