generated from GSM-MSG/MSG-Repository-Generator
-
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
1 parent
7c14d12
commit 02ee2b7
Showing
4 changed files
with
119 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
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 fs from 'fs' | ||
import formidable from 'formidable' | ||
import serverApi from '@api/serverApi' | ||
import { withHandler } from '@features/server/libs' | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
} | ||
|
||
export default withHandler({ | ||
methods: ['POST'], | ||
checkAccess: true, | ||
handler: async ({ req, res, accessToken }) => { | ||
const form = formidable({}) | ||
const [_, files] = await form.parse(req) | ||
|
||
const file = files.file?.[0] | ||
if (!file || !file.originalFilename) return | ||
|
||
const fileStream = fs.readFileSync(file.filepath) | ||
const formData = new FormData() | ||
formData.append('file', new Blob([fileStream]), file.originalFilename) | ||
|
||
const { data, status } = await serverApi({ | ||
method: 'POST', | ||
url: '/file/image', | ||
data: formData, | ||
headers: { | ||
...req.headers, | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}) | ||
|
||
return res.status(status).json(data) | ||
}, | ||
}) |
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 fs from 'fs' | ||
import formidable from 'formidable' | ||
import serverApi from '@api/serverApi' | ||
import { withHandler } from '@features/server/libs' | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
} | ||
|
||
export default withHandler({ | ||
methods: ['POST'], | ||
checkAccess: true, | ||
handler: async ({ req, res, accessToken }) => { | ||
const form = formidable({}) | ||
const [_, files] = await form.parse(req) | ||
|
||
const file = files.file?.[0] | ||
if (!file || !file.originalFilename) return | ||
|
||
const fileStream = fs.readFileSync(file.filepath) | ||
const formData = new FormData() | ||
formData.append('file', new Blob([fileStream]), file.originalFilename) | ||
|
||
const { data, status } = await serverApi({ | ||
method: 'POST', | ||
url: '/file', | ||
data: formData, | ||
headers: { | ||
...req.headers, | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}) | ||
|
||
return res.status(status).json(data) | ||
}, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.