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
e542a030
Unverified
Commit
e542a030
authored
2 years ago
by
Kagami Sascha Rosylight
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(backend/URLPreviewService): エラーでHTTP 422を出すように (#10339)
* fix(backend/URLPreviewService): エラーでHTTP 402を出すように * fix import
parent
2e051c58
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
packages/backend/src/server/web/UrlPreviewService.ts
+12
-6
12 additions, 6 deletions
packages/backend/src/server/web/UrlPreviewService.ts
packages/backend/test/e2e/endpoints.ts
+8
-0
8 additions, 0 deletions
packages/backend/test/e2e/endpoints.ts
with
20 additions
and
6 deletions
packages/backend/src/server/web/UrlPreviewService.ts
+
12
−
6
View file @
e542a030
import
{
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
summaly
}
from
'
summaly
'
;
import
{
DI
}
from
'
@/di-symbols.js
'
;
import
type
{
UsersRepository
}
from
'
@/models/index.js
'
;
import
type
{
Config
}
from
'
@/config.js
'
;
import
{
MetaService
}
from
'
@/core/MetaService.js
'
;
import
{
HttpRequestService
}
from
'
@/core/HttpRequestService.js
'
;
...
...
@@ -9,6 +8,7 @@ import type Logger from '@/logger.js';
import
{
query
}
from
'
@/misc/prelude/url.js
'
;
import
{
LoggerService
}
from
'
@/core/LoggerService.js
'
;
import
{
bindThis
}
from
'
@/decorators.js
'
;
import
{
ApiError
}
from
'
@/server/api/error.js
'
;
import
type
{
FastifyRequest
,
FastifyReply
}
from
'
fastify
'
;
@
Injectable
()
...
...
@@ -40,9 +40,9 @@ export class UrlPreviewService {
@
bindThis
public
async
handle
(
request
:
FastifyRequest
<
{
Querystring
:
{
url
:
string
;
lang
:
string
;
}
}
>
,
request
:
FastifyRequest
<
{
Querystring
:
{
url
:
string
;
lang
?
:
string
;
}
}
>
,
reply
:
FastifyReply
,
)
{
)
:
Promise
<
object
|
undefined
>
{
const
url
=
request
.
query
.
url
;
if
(
typeof
url
!==
'
string
'
)
{
reply
.
code
(
400
);
...
...
@@ -78,7 +78,7 @@ export class UrlPreviewService {
this
.
logger
.
succ
(
`Got preview of
${
url
}
:
${
summary
.
title
}
`
);
if
(
summary
.
url
&&
!
(
summary
.
url
.
startsWith
(
'
http://
'
)
||
summary
.
url
.
startsWith
(
'
https://
'
)))
{
if
(
!
(
summary
.
url
.
startsWith
(
'
http://
'
)
||
summary
.
url
.
startsWith
(
'
https://
'
)))
{
throw
new
Error
(
'
unsupported schema included
'
);
}
...
...
@@ -95,9 +95,15 @@ export class UrlPreviewService {
return
summary
;
}
catch
(
err
)
{
this
.
logger
.
warn
(
`Failed to get preview of
${
url
}
:
${
err
}
`
);
reply
.
code
(
200
);
reply
.
code
(
422
);
reply
.
header
(
'
Cache-Control
'
,
'
max-age=86400, immutable
'
);
return
{};
return
{
error
:
new
ApiError
({
message
:
'
Failed to get preview
'
,
code
:
'
URL_PREVIEW_FAILED
'
,
id
:
'
09d01cb5-53b9-4856-82e5-38a50c290a3b
'
,
}),
};
}
}
}
This diff is collapsed.
Click to expand it.
packages/backend/test/e2e/endpoints.ts
+
8
−
0
View file @
e542a030
...
...
@@ -841,4 +841,12 @@ describe('Endpoints', () => {
assert
.
strictEqual
(
res
.
body
[
0
].
id
,
carolPost
.
id
);
});
});
describe
(
'
URL preview
'
,
()
=>
{
test
(
'
Error from summaly becomes HTTP 422
'
,
async
()
=>
{
const
res
=
await
simpleGet
(
'
/url?url=https://e:xample.com
'
);
assert
.
strictEqual
(
res
.
status
,
422
);
assert
.
strictEqual
(
res
.
body
.
error
.
code
,
'
URL_PREVIEW_FAILED
'
);
});
});
});
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