-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ian Walter
committed
Dec 31, 2021
1 parent
c7dba13
commit cd7fd2e
Showing
9 changed files
with
75 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
.env | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { S3Client } from '@aws-sdk/client-s3' | ||
|
||
export default function storagePlugin (app, opts) { | ||
app.storage = new S3Client(opts) | ||
app.use(function storageMiddleware (req, res, next) { | ||
req.storage = app.storage | ||
next() | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { promises as fs } from 'fs' | ||
import { nanoid } from 'nanoid' | ||
import { create } from '@generates/whip' | ||
import { PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3' | ||
import storage from '../../index.js' | ||
|
||
const Bucket = 'whip' | ||
const fileUrl = new URL('josh-duncan-trunk-bay.jpg', import.meta.url) | ||
const app = create() | ||
|
||
app.add({ | ||
plugin: storage, | ||
opts: { | ||
region: 'us-east-1', | ||
forcePathStyle: true, | ||
endpoint: 'http://localhost:9000', | ||
credentials: { accessKeyId: 'whip', secretAccessKey: 'dontWasteNoTime' } | ||
} | ||
}) | ||
|
||
let Key | ||
app.get('/', async function download (req, res) { | ||
if (Key) { | ||
const out = await req.storage.send(new GetObjectCommand({ Bucket, Key })) | ||
// TODO: | ||
// req.logger.info('GetObjectCommand response', out) | ||
res.set('Content-Type', 'image/jpeg').send(out.Body) | ||
} else { | ||
Key = nanoid() | ||
const Body = await fs.readFile(fileUrl) | ||
const command = new PutObjectCommand({ Bucket, Key, Body }) | ||
const out = await req.storage.send(command) | ||
req.logger.info('PutObjectCommand response', out) | ||
res.send('File uploaded') | ||
} | ||
}) | ||
|
||
export default app |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
import { test } from '@ianwalter/bff' | ||
|
||
test('', t => { | ||
|
||
}) |
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