Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Moecube Accounts Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Moecube Accounts Backend
Commits
5c00c181
Commit
5c00c181
authored
Jul 09, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix small file upload
parent
1f39562e
Pipeline
#14476
failed with stages
in 1 minute and 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
1 deletion
+3
-1
src/controllers/upload.ts
src/controllers/upload.ts
+3
-1
No files found.
src/controllers/upload.ts
View file @
5c00c181
...
@@ -25,6 +25,7 @@ export const UploadImage = async (ctx: Context) => {
...
@@ -25,6 +25,7 @@ export const UploadImage = async (ctx: Context) => {
const
uploadFiles
:
{
fieldname
:
string
,
file
:
Readable
,
fname
:
string
,
encoding
:
string
,
mimeType
:
string
}[]
=
[]
const
uploadFiles
:
{
fieldname
:
string
,
file
:
Readable
,
fname
:
string
,
encoding
:
string
,
mimeType
:
string
}[]
=
[]
const
results
:
any
[]
=
[];
const
results
:
any
[]
=
[];
const
waitForUploads
:
Promise
<
any
>
[]
=
[];
const
waitForUploads
:
Promise
<
any
>
[]
=
[];
const
filesToUpload
:
Promise
<
Readable
>
[]
=
[];
await
busboy
(
ctx
.
req
,
{
await
busboy
(
ctx
.
req
,
{
onFile
:
async
(
fieldname
,
_file
,
fname
,
encoding
,
mimeType
)
=>
{
onFile
:
async
(
fieldname
,
_file
,
fname
,
encoding
,
mimeType
)
=>
{
const
file
=
new
Readable
().
wrap
(
_file
);
const
file
=
new
Readable
().
wrap
(
_file
);
...
@@ -35,7 +36,7 @@ export const UploadImage = async (ctx: Context) => {
...
@@ -35,7 +36,7 @@ export const UploadImage = async (ctx: Context) => {
if
([
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
webp
'
].
indexOf
(
ext
)
===
-
1
)
{
if
([
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
,
'
webp
'
].
indexOf
(
ext
)
===
-
1
)
{
throw
new
Error
(
'
Unsupported image type
'
);
throw
new
Error
(
'
Unsupported image type
'
);
}
}
file
.
pause
();
const
filename
=
`avatars/
${
uuid
.
v1
()}
.
${
ext
}
`
;
const
filename
=
`avatars/
${
uuid
.
v1
()}
.
${
ext
}
`
;
console
.
log
(
`uploading
${
fname
}
to
${
filename
}
`
)
console
.
log
(
`uploading
${
fname
}
to
${
filename
}
`
)
const
upload
=
new
Upload
({
const
upload
=
new
Upload
({
...
@@ -52,6 +53,7 @@ export const UploadImage = async (ctx: Context) => {
...
@@ -52,6 +53,7 @@ export const UploadImage = async (ctx: Context) => {
}
}
});
});
console
.
log
(
`waiting`
);
console
.
log
(
`waiting`
);
filesToUpload
.
forEach
((
file
)
=>
file
.
resume
());
await
Promise
.
all
(
waitForUploads
);
await
Promise
.
all
(
waitForUploads
);
console
.
log
(
`finish`
);
console
.
log
(
`finish`
);
ctx
.
body
=
results
;
ctx
.
body
=
results
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment