Init sqlite take 2

This commit is contained in:
advplyr 2023-07-04 18:14:44 -05:00
parent d86a3b3dc2
commit cf7fd315b6
88 changed files with 7017 additions and 692 deletions

View file

@ -1,9 +1,15 @@
const uuidv4 = require("uuid").v4
class MediaProgress {
constructor(progress) {
this.id = null
this.userId = null
this.libraryItemId = null
this.episodeId = null // For podcasts
this.mediaItemId = null // For use in new data model
this.mediaItemType = null // For use in new data model
this.duration = null
this.progress = null // 0 to 1
this.currentTime = null // seconds
@ -25,8 +31,11 @@ class MediaProgress {
toJSON() {
return {
id: this.id,
userId: this.userId,
libraryItemId: this.libraryItemId,
episodeId: this.episodeId,
mediaItemId: this.mediaItemId,
mediaItemType: this.mediaItemType,
duration: this.duration,
progress: this.progress,
currentTime: this.currentTime,
@ -42,8 +51,11 @@ class MediaProgress {
construct(progress) {
this.id = progress.id
this.userId = progress.userId
this.libraryItemId = progress.libraryItemId
this.episodeId = progress.episodeId
this.mediaItemId = progress.mediaItemId
this.mediaItemType = progress.mediaItemType
this.duration = progress.duration || 0
this.progress = progress.progress
this.currentTime = progress.currentTime || 0
@ -60,10 +72,16 @@ class MediaProgress {
return !this.isFinished && (this.progress > 0 || (this.ebookLocation != null && this.ebookProgress > 0))
}
setData(libraryItemId, progress, episodeId = null) {
this.id = episodeId ? `${libraryItemId}-${episodeId}` : libraryItemId
this.libraryItemId = libraryItemId
setData(libraryItem, progress, episodeId, userId) {
this.id = uuidv4()
this.userId = userId
this.libraryItemId = libraryItem.id
this.episodeId = episodeId
// PodcastEpisodeId or BookId
this.mediaItemId = episodeId || libraryItem.media.id
this.mediaItemType = episodeId ? 'podcastEpisode' : 'book'
this.duration = progress.duration || 0
this.progress = Math.min(1, (progress.progress || 0))
this.currentTime = progress.currentTime || 0

View file

@ -5,6 +5,7 @@ const MediaProgress = require('./MediaProgress')
class User {
constructor(user) {
this.id = null
this.oldUserId = null // TODO: Temp for keeping old access tokens
this.username = null
this.pash = null
this.type = null
@ -73,6 +74,7 @@ class User {
toJSON() {
return {
id: this.id,
oldUserId: this.oldUserId,
username: this.username,
pash: this.pash,
type: this.type,
@ -93,6 +95,7 @@ class User {
toJSONForBrowser(hideRootToken = false, minimal = false) {
const json = {
id: this.id,
oldUserId: this.oldUserId,
username: this.username,
type: this.type,
token: (this.type === 'root' && hideRootToken) ? '' : this.token,
@ -126,6 +129,7 @@ class User {
}
return {
id: this.id,
oldUserId: this.oldUserId,
username: this.username,
type: this.type,
session,
@ -137,6 +141,7 @@ class User {
construct(user) {
this.id = user.id
this.oldUserId = user.oldUserId
this.username = user.username
this.pash = user.pash
this.type = user.type
@ -320,7 +325,7 @@ class User {
if (!itemProgress) {
const newItemProgress = new MediaProgress()
newItemProgress.setData(libraryItem.id, updatePayload, episodeId)
newItemProgress.setData(libraryItem, updatePayload, episodeId, this.id)
this.mediaProgress.push(newItemProgress)
return true
}
@ -336,12 +341,6 @@ class User {
return true
}
removeMediaProgressForLibraryItem(libraryItemId) {
if (!this.mediaProgress.some(lip => lip.libraryItemId == libraryItemId)) return false
this.mediaProgress = this.mediaProgress.filter(lip => lip.libraryItemId != libraryItemId)
return true
}
checkCanAccessLibrary(libraryId) {
if (this.permissions.accessAllLibraries) return true
if (!this.librariesAccessible) return false