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
270a5299
Unverified
Commit
270a5299
authored
Aug 05, 2023
by
boojack
Committed by
GitHub
Aug 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update resource type checks (#2081)
parent
cc400da4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
36 deletions
+39
-36
MemoResourceListView.tsx
web/src/components/MemoResourceListView.tsx
+5
-7
ResourceCover.tsx
web/src/components/ResourceCover.tsx
+1
-27
ResourceItemDropdown.tsx
web/src/components/ResourceItemDropdown.tsx
+2
-2
resource.ts
web/src/utils/resource.ts
+31
-0
No files found.
web/src/components/MemoResourceListView.tsx
View file @
270a5299
import
{
ImageList
,
ImageListItem
,
useMediaQuery
}
from
"@mui/material"
;
import
{
absolutifyLink
}
from
"@/helpers/utils"
;
import
{
getResourceUrl
}
from
"@/utils/resource"
;
import
{
getResource
Type
,
getResource
Url
}
from
"@/utils/resource"
;
import
SquareDiv
from
"./kit/SquareDiv"
;
import
MemoResource
from
"./MemoResource"
;
import
showPreviewImageDialog
from
"./PreviewImageDialog"
;
...
...
@@ -24,17 +24,15 @@ const MemoResourceListView: React.FC<Props> = (props: Props) => {
...
props
,
};
const
matches
=
useMediaQuery
(
"(min-width:640px)"
);
const
imageResourceList
=
resourceList
.
filter
((
resource
)
=>
resource
.
type
.
startsWith
(
"image"
));
const
imageResourceList
=
resourceList
.
filter
((
resource
)
=>
getResourceType
(
resource
)
.
startsWith
(
"image"
));
const
videoResourceList
=
resourceList
.
filter
((
resource
)
=>
resource
.
type
.
startsWith
(
"video"
));
const
otherResourceList
=
resourceList
.
filter
(
(
resource
)
=>
!
imageResourceList
.
includes
(
resource
)
&&
!
videoResourceList
.
includes
(
resource
)
);
const
imgUrls
=
imageResourceList
.
filter
((
resource
)
=>
resource
.
type
.
startsWith
(
"image"
))
.
map
((
resource
)
=>
{
return
getResourceUrl
(
resource
);
});
const
imgUrls
=
imageResourceList
.
map
((
resource
)
=>
{
return
getResourceUrl
(
resource
);
});
const
handleImageClick
=
(
imgUrl
:
string
)
=>
{
const
index
=
imgUrls
.
findIndex
((
url
)
=>
url
===
imgUrl
);
...
...
web/src/components/ResourceCover.tsx
View file @
270a5299
import
React
from
"react"
;
import
{
getResourceUrl
}
from
"@/utils/resource"
;
import
{
getResource
Type
,
getResource
Url
}
from
"@/utils/resource"
;
import
Icon
from
"./Icon"
;
import
SquareDiv
from
"./kit/SquareDiv"
;
import
showPreviewImageDialog
from
"./PreviewImageDialog"
;
...
...
@@ -9,32 +9,6 @@ interface ResourceCoverProps {
resource
:
Resource
;
}
const
getResourceType
=
(
resource
:
Resource
)
=>
{
if
(
resource
.
type
.
startsWith
(
"image"
))
{
return
"image/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"video"
))
{
return
"video/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"audio"
))
{
return
"audio/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"text"
))
{
return
"text/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/epub+zip"
))
{
return
"application/epub+zip"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/pdf"
))
{
return
"application/pdf"
;
}
else
if
(
resource
.
type
.
includes
(
"word"
))
{
return
"application/msword"
;
}
else
if
(
resource
.
type
.
includes
(
"excel"
))
{
return
"application/msexcel"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/zip"
))
{
return
"application/zip"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/x-java-archive"
))
{
return
"application/x-java-archive"
;
}
else
{
return
"application/octet-stream"
;
}
};
const
ResourceCover
=
({
resource
}:
ResourceCoverProps
)
=>
{
const
resourceType
=
getResourceType
(
resource
);
const
resourceUrl
=
getResourceUrl
(
resource
);
...
...
web/src/components/ResourceItemDropdown.tsx
View file @
270a5299
...
...
@@ -3,7 +3,7 @@ import React from "react";
import
toast
from
"react-hot-toast"
;
import
{
useResourceStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
getResourceUrl
}
from
"@/utils/resource"
;
import
{
getResource
Type
,
getResource
Url
}
from
"@/utils/resource"
;
import
showChangeResourceFilenameDialog
from
"./ChangeResourceFilenameDialog"
;
import
{
showCommonDialog
}
from
"./Dialog/CommonDialog"
;
import
Icon
from
"./Icon"
;
...
...
@@ -20,7 +20,7 @@ const ResourceItemDropdown = ({ resource }: Props) => {
const
handlePreviewBtnClick
=
(
resource
:
Resource
)
=>
{
const
resourceUrl
=
getResourceUrl
(
resource
);
if
(
resource
.
type
.
startsWith
(
"image"
))
{
if
(
getResourceType
(
resource
)
.
startsWith
(
"image"
))
{
showPreviewImageDialog
([
getResourceUrl
(
resource
)],
0
);
}
else
{
window
.
open
(
resourceUrl
);
...
...
web/src/utils/resource.ts
View file @
270a5299
...
...
@@ -5,3 +5,34 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
return
`
${
withOrigin
?
window
.
location
.
origin
:
""
}
/o/r/
${
resource
.
id
}
`
;
};
export
const
getResourceType
=
(
resource
:
Resource
)
=>
{
if
(
resource
.
type
.
startsWith
(
"image"
)
&&
isImage
(
resource
.
type
))
{
return
"image/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"video"
))
{
return
"video/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"audio"
))
{
return
"audio/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"text"
))
{
return
"text/*"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/epub+zip"
))
{
return
"application/epub+zip"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/pdf"
))
{
return
"application/pdf"
;
}
else
if
(
resource
.
type
.
includes
(
"word"
))
{
return
"application/msword"
;
}
else
if
(
resource
.
type
.
includes
(
"excel"
))
{
return
"application/msexcel"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/zip"
))
{
return
"application/zip"
;
}
else
if
(
resource
.
type
.
startsWith
(
"application/x-java-archive"
))
{
return
"application/x-java-archive"
;
}
else
{
return
"application/octet-stream"
;
}
};
// 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"
;
};
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