mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
implement refeshTrackCache
This commit is contained in:
parent
89085b9b6a
commit
e686bf31ad
@ -4,6 +4,8 @@ import classnames from "classnames"
|
|||||||
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"
|
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"
|
||||||
import UploadButton from "components/UploadButton"
|
import UploadButton from "components/UploadButton"
|
||||||
|
|
||||||
|
import PlaylistModel from "models/playlists"
|
||||||
|
|
||||||
import { Icons } from "components/Icons"
|
import { Icons } from "components/Icons"
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
@ -28,6 +30,10 @@ const FileItemEditor = (props) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onRefreshCache = () => {
|
||||||
|
props.onRefreshCache(track)
|
||||||
|
}
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
if (typeof props.close === "function") {
|
if (typeof props.close === "function") {
|
||||||
props.close()
|
props.close()
|
||||||
@ -50,19 +56,19 @@ const FileItemEditor = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="fileItemEditor_field_thumnail">
|
<div className="fileItemEditor_field_thumnail">
|
||||||
<img src={track.thumbnail} />
|
<img src={track.cover ?? track.thumbnail} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="fileItemEditor_actions">
|
<div className="fileItemEditor_actions">
|
||||||
<UploadButton
|
<UploadButton
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
onUploadDone={(file) => handleChange("thumbnail", file.url)}
|
onUploadDone={(file) => handleChange("cover", file.url)}
|
||||||
/>
|
/>
|
||||||
{
|
{
|
||||||
track.thumbnail && <antd.Button
|
(track.cover ?? track.thumbnail) && <antd.Button
|
||||||
icon={<Icons.MdClose />}
|
icon={<Icons.MdClose />}
|
||||||
type="text"
|
type="text"
|
||||||
onClick={() => handleChange("thumbnail", null)}
|
onClick={() => handleChange("cover", null)}
|
||||||
>
|
>
|
||||||
Remove
|
Remove
|
||||||
</antd.Button>
|
</antd.Button>
|
||||||
@ -149,6 +155,15 @@ const FileItemEditor = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="fileItemEditor_actions">
|
<div className="fileItemEditor_actions">
|
||||||
|
{
|
||||||
|
track._id && <antd.Button
|
||||||
|
type="text"
|
||||||
|
icon={<Icons.MdRefresh />}
|
||||||
|
onClick={onRefreshCache}
|
||||||
|
>
|
||||||
|
Refresh Cache
|
||||||
|
</antd.Button>
|
||||||
|
}
|
||||||
<antd.Button
|
<antd.Button
|
||||||
type="text"
|
type="text"
|
||||||
icon={<Icons.MdClose />}
|
icon={<Icons.MdClose />}
|
||||||
@ -194,7 +209,7 @@ const FileListItem = (props) => {
|
|||||||
|
|
||||||
<div className="fileListItem_cover">
|
<div className="fileListItem_cover">
|
||||||
<img
|
<img
|
||||||
src={props.track?.thumbnail}
|
src={props.track.cover ?? props.track?.thumbnail}
|
||||||
alt="Track cover"
|
alt="Track cover"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -276,12 +291,27 @@ export default (props) => {
|
|||||||
const onClickEditTrack = (track) => {
|
const onClickEditTrack = (track) => {
|
||||||
app.DrawerController.open("track_editor", FileItemEditor, {
|
app.DrawerController.open("track_editor", FileItemEditor, {
|
||||||
type: "drawer",
|
type: "drawer",
|
||||||
|
props: {
|
||||||
|
width: "25vw",
|
||||||
|
minWidth: "500px",
|
||||||
|
},
|
||||||
componentProps: {
|
componentProps: {
|
||||||
track,
|
track,
|
||||||
onSave: (newTrackData) => {
|
onSave: (newTrackData) => {
|
||||||
console.log("Saving track", newTrackData)
|
console.log("Saving track", newTrackData)
|
||||||
|
|
||||||
props.handleTrackInfoChange(newTrackData.uid, newTrackData)
|
props.handleTrackInfoChange(newTrackData.uid, newTrackData)
|
||||||
|
},
|
||||||
|
onRefreshCache: () => {
|
||||||
|
console.log("Refreshing cache for track", track.uid)
|
||||||
|
|
||||||
|
PlaylistModel.refreshTrackCache(track._id)
|
||||||
|
.catch(() => {
|
||||||
|
app.message.error("Failed to refresh cache for track")
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
app.message.success("Successfully refreshed cache for track")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,20 @@ export default class PlaylistsModel {
|
|||||||
return globalThis.__comty_shared_state.instances["music"]
|
return globalThis.__comty_shared_state.instances["music"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static refreshTrackCache = async (track_id) => {
|
||||||
|
if (!track_id) {
|
||||||
|
throw new Error("Track ID is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await request({
|
||||||
|
instance: PlaylistsModel.api_instance,
|
||||||
|
method: "POST",
|
||||||
|
url: `/tracks/${track_id}/refresh-cache`,
|
||||||
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
static putPlaylist = async (payload) => {
|
static putPlaylist = async (payload) => {
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
throw new Error("Payload is required")
|
throw new Error("Payload is required")
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import { Track } from "@models"
|
||||||
|
import { NotFoundError } from "@classes/Errors"
|
||||||
|
import getEnhancedLyricsFromTrack from "@services/getEnhancedLyricsFromTrack"
|
||||||
|
|
||||||
|
export default async (req, res) => {
|
||||||
|
const { track_id } = req.params
|
||||||
|
|
||||||
|
let track = await Track.findOne({
|
||||||
|
_id: track_id,
|
||||||
|
public: true,
|
||||||
|
}).catch((err) => {
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!track) {
|
||||||
|
return new NotFoundError(req, res, "Track not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (track.lyricsEnabled) {
|
||||||
|
const enhancedLyrics = await getEnhancedLyricsFromTrack(track, { req }).catch((err) => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (enhancedLyrics) {
|
||||||
|
await global.redis.set(`lyrics:${track._id.toString()}`, JSON.stringify(enhancedLyrics), "EX", 60 * 60 * 24 * 30)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json({
|
||||||
|
success: true,
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user