mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
improve TrackManifest
This commit is contained in:
parent
ec6003558d
commit
534463cfa2
@ -1,22 +1,7 @@
|
|||||||
import jsmediatags from "jsmediatags/dist/jsmediatags.min.js"
|
import jsmediatags from "jsmediatags/dist/jsmediatags.min.js"
|
||||||
import { FastAverageColor } from "fast-average-color"
|
import { FastAverageColor } from "fast-average-color"
|
||||||
|
|
||||||
async function uploadBinaryArrayToStorage(bin, args) {
|
import MusicService from "@models/music"
|
||||||
const { format, data } = bin
|
|
||||||
|
|
||||||
const filenameExt = format.split("/")[1]
|
|
||||||
const filename = `cover.${filenameExt}`
|
|
||||||
|
|
||||||
const byteArray = new Uint8Array(data)
|
|
||||||
const blob = new Blob([byteArray], { type: data.type })
|
|
||||||
|
|
||||||
// create a file object
|
|
||||||
const file = new File([blob], filename, {
|
|
||||||
type: format,
|
|
||||||
})
|
|
||||||
|
|
||||||
return await app.cores.remoteStorage.uploadFile(file, args)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class TrackManifest {
|
export default class TrackManifest {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
@ -57,34 +42,23 @@ export default class TrackManifest {
|
|||||||
this.lyrics_enabled = params.lyrics_enabled
|
this.lyrics_enabled = params.lyrics_enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.cover.startsWith("http")) {
|
|
||||||
try {
|
|
||||||
this.analyzeCoverColor()
|
|
||||||
} catch (error) {
|
|
||||||
// so bad...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
uid = null
|
_id = null // used for api requests
|
||||||
|
uid = null // used for internal
|
||||||
|
|
||||||
cover = "https://storage.ragestudio.net/comty-static-assets/default_song.png"
|
cover = "https://storage.ragestudio.net/comty-static-assets/default_song.png"
|
||||||
|
|
||||||
title = "Untitled"
|
title = "Untitled"
|
||||||
|
|
||||||
album = "Unknown"
|
album = "Unknown"
|
||||||
|
|
||||||
artist = "Unknown"
|
artist = "Unknown"
|
||||||
|
|
||||||
source = null
|
source = null
|
||||||
|
metadata = null
|
||||||
|
|
||||||
metadata = {}
|
// Extended from db
|
||||||
|
|
||||||
lyrics_enabled = false
|
lyrics_enabled = false
|
||||||
|
|
||||||
analyzedMetadata = null
|
liked = null
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
if (this.params.file) {
|
if (this.params.file) {
|
||||||
@ -104,7 +78,9 @@ export default class TrackManifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.metadata.tags.picture) {
|
if (this.metadata.tags.picture) {
|
||||||
const coverUpload = await uploadBinaryArrayToStorage(this.metadata.tags.picture)
|
this.cover = app.cores.remoteStorage.binaryArrayToFile(this.metadata.tags.picture, this.title)
|
||||||
|
|
||||||
|
const coverUpload = await app.cores.remoteStorage.uploadFile(this.cover)
|
||||||
|
|
||||||
this.cover = coverUpload.url
|
this.cover = coverUpload.url
|
||||||
}
|
}
|
||||||
@ -147,4 +123,12 @@ export default class TrackManifest {
|
|||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchLikeStatus = async () => {
|
||||||
|
if (!this._id) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return await MusicService.isItemFavourited("track", this._id)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user