Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
72630039
Unverified
Commit
72630039
authored
Aug 06, 2023
by
boojack
Committed by
GitHub
Aug 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update image checks (#2092)
parent
5d5d8de9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
ResourceIcon.tsx
web/src/components/ResourceIcon.tsx
+2
-2
resource.ts
web/src/utils/resource.ts
+7
-2
No files found.
web/src/components/ResourceIcon.tsx
View file @
72630039
import
classNames
from
"classnames"
;
import
{
getResourceUrl
}
from
"@/utils/resource"
;
import
{
getResource
Type
,
getResource
Url
}
from
"@/utils/resource"
;
import
Icon
from
"./Icon"
;
import
showPreviewImageDialog
from
"./PreviewImageDialog"
;
import
SquareDiv
from
"./kit/SquareDiv"
;
...
...
@@ -12,7 +12,7 @@ interface Props {
const
ResourceIcon
=
(
props
:
Props
)
=>
{
const
{
className
,
resource
}
=
props
;
if
(
resource
.
type
.
includes
(
"image"
))
{
if
(
getResourceType
(
resource
).
startsWith
(
"image"
))
{
const
url
=
getResourceUrl
(
resource
);
return
(
<
SquareDiv
key=
{
resource
.
id
}
className=
{
classNames
(
"cursor-pointer rounded hover:shadow"
,
className
)
}
>
...
...
web/src/utils/resource.ts
View file @
72630039
...
...
@@ -7,7 +7,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
};
export
const
getResourceType
=
(
resource
:
Resource
)
=>
{
if
(
resource
.
type
.
startsWith
(
"image"
)
&&
isImage
(
resource
.
type
))
{
if
(
isImage
(
resource
.
type
))
{
return
"image/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"video"
))
{
return
"video/*"
;
...
...
@@ -34,5 +34,10 @@ export const getResourceType = (resource: Resource) => {
// isImage returns true if the given mime type is an image.
export
const
isImage
=
(
t
:
string
)
=>
{
return
t
===
"image/jpeg"
||
t
===
"image/png"
||
t
===
"image/gif"
||
t
===
"image/svg+xml"
||
t
===
"image/webp"
;
// Don't show PSDs as images.
return
t
.
startsWith
(
"image/"
)
&&
!
isPSD
(
t
);
};
const
isPSD
=
(
t
:
string
)
=>
{
return
t
===
"image/vnd.adobe.photoshop"
||
t
===
"image/x-photoshop"
||
t
===
"image/photoshop"
;
};
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