Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
cbbdc987
Commit
cbbdc987
authored
5 years ago
by
MeiMei
Committed by
syuilo
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
/files/ 下のヘッダ設定タイミングを修正 (#5650)
parent
4229065a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/server/file/index.ts
+2
-7
2 additions, 7 deletions
src/server/file/index.ts
src/server/file/send-drive-file.ts
+10
-5
10 additions, 5 deletions
src/server/file/send-drive-file.ts
with
12 additions
and
12 deletions
src/server/file/index.ts
+
2
−
7
View file @
cbbdc987
...
...
@@ -12,19 +12,14 @@ import sendDriveFile from './send-drive-file';
const
app
=
new
Koa
();
app
.
use
(
cors
());
app
.
use
(
async
(
ctx
,
next
)
=>
{
// Cache 365days
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=31536000, immutable
'
);
await
next
();
});
// Init router
const
router
=
new
Router
();
router
.
get
(
'
/app-default.jpg
'
,
ctx
=>
{
const
file
=
fs
.
createReadStream
(
`
${
__dirname
}
/assets/dummy.png`
);
ctx
.
set
(
'
Content-Type
'
,
'
image/jpeg
'
);
ctx
.
body
=
file
;
ctx
.
set
(
'
Content-Type
'
,
'
image/jpeg
'
);
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=31536000, immutable
'
);
});
router
.
get
(
'
/:key
'
,
sendDriveFile
);
...
...
This diff is collapsed.
Click to expand it.
src/server/file/send-drive-file.ts
+
10
−
5
View file @
cbbdc987
...
...
@@ -11,6 +11,7 @@ const assets = `${__dirname}/../../server/file/assets/`;
const
commonReadableHandlerGenerator
=
(
ctx
:
Koa
.
Context
)
=>
(
e
:
Error
):
void
=>
{
serverLogger
.
error
(
e
);
ctx
.
status
=
500
;
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=300
'
);
};
export
default
async
function
(
ctx
:
Koa
.
Context
)
{
...
...
@@ -25,12 +26,14 @@ export default async function(ctx: Koa.Context) {
if
(
file
==
null
)
{
ctx
.
status
=
404
;
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=86400
'
);
await
send
(
ctx
as
any
,
'
/dummy.png
'
,
{
root
:
assets
});
return
;
}
if
(
!
file
.
storedInternal
)
{
ctx
.
status
=
204
;
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=86400
'
);
return
;
}
...
...
@@ -38,19 +41,21 @@ export default async function(ctx: Koa.Context) {
const
isWebpublic
=
file
.
webpublicAccessKey
===
key
;
if
(
isThumbnail
)
{
ctx
.
body
=
InternalStorage
.
read
(
key
);
ctx
.
set
(
'
Content-Type
'
,
'
image/jpeg
'
);
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=31536000, immutable
'
);
ctx
.
set
(
'
Content-Disposition
'
,
contentDisposition
(
'
inline
'
,
`
${
rename
(
file
.
name
,
{
suffix
:
'
-thumb
'
,
extname
:
'
.jpeg
'
})}
`
));
ctx
.
body
=
InternalStorage
.
read
(
key
);
}
else
if
(
isWebpublic
)
{
ctx
.
body
=
InternalStorage
.
read
(
key
);
ctx
.
set
(
'
Content-Type
'
,
file
.
type
===
'
image/apng
'
?
'
image/png
'
:
file
.
type
);
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=31536000, immutable
'
);
ctx
.
set
(
'
Content-Disposition
'
,
contentDisposition
(
'
inline
'
,
`
${
rename
(
file
.
name
,
{
suffix
:
'
-web
'
})}
`
));
ctx
.
body
=
InternalStorage
.
read
(
key
);
}
else
{
ctx
.
set
(
'
Content-Disposition
'
,
contentDisposition
(
'
inline
'
,
`
${
file
.
name
}
`
));
const
readable
=
InternalStorage
.
read
(
file
.
accessKey
!
);
readable
.
on
(
'
error
'
,
commonReadableHandlerGenerator
(
ctx
));
ctx
.
set
(
'
Content-Type
'
,
file
.
type
);
ctx
.
body
=
readable
;
ctx
.
set
(
'
Content-Type
'
,
file
.
type
);
ctx
.
set
(
'
Cache-Control
'
,
'
max-age=31536000, immutable
'
);
ctx
.
set
(
'
Content-Disposition
'
,
contentDisposition
(
'
inline
'
,
`
${
file
.
name
}
`
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment