Skip to content

Commit

Permalink
merged komga tracker functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
FaizanDurrani committed Oct 23, 2023
1 parent d7a1a4f commit 67f08c8
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions src/Paperback/Paperback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { Chapter,
TagSection,
BadgeColor,
SourceInterceptor,
SourceIntents} from '@paperback/types'
SourceIntents,
MangaProgressProviding,
TrackerActionQueue,
DUIForm
} from '@paperback/types'
import { parseLangCode } from './Languages'
import { resetSettingsButton,
serverSettingsMenu,
Expand Down Expand Up @@ -53,7 +57,7 @@ export const PaperbackInfo: SourceInfo = {
type: BadgeColor.RED
},
],
intents: SourceIntents.MANGA_CHAPTERS | SourceIntents.HOMEPAGE_SECTIONS | SourceIntents.SETTINGS_UI
intents: SourceIntents.MANGA_CHAPTERS | SourceIntents.HOMEPAGE_SECTIONS | SourceIntents.SETTINGS_UI | SourceIntents.MANGA_TRACKING
}
const SUPPORTED_IMAGE_TYPES = [
'image/jpeg',
Expand Down Expand Up @@ -496,4 +500,68 @@ export class Paperback extends Source {
}
}
}

async getMangaProgressManagementForm(mangaId: string): Promise<DUIForm> {
return App.createDUIForm({
sections: async () => {
return [
App.createDUISection({
id: 'mangaId',
rows: async () => [
App.createDUILabel({
id: 'id',
label: 'Manga id: ' + mangaId,
value: undefined
}),
App.createDUILabel({
id: 'info',
label: 'The app will sync read chapters to the Komga server',
value: undefined
})
],
isHidden: false
})
]
},
onSubmit: () => {
return Promise.resolve()
},
})
}

async processChapterReadActionQueue(actionQueue: TrackerActionQueue): Promise<void> {
const chapterReadActions = await actionQueue.queuedChapterReadActions()
const komgaAPI = await getKomgaAPI(this.stateManager)

for (const readAction of chapterReadActions) {
if (readAction.sourceId != 'Komga') {
console.log(`Manga ${readAction.mangaId} from source ${readAction.sourceId} can not be used as it does not come from Komga. Discarding`)
await actionQueue.discardChapterReadAction(readAction)
} else {
try {
// The app only support completed read status so the last page read is not important and set to 1
const request = App.createRequest({
url: `${komgaAPI}/books/${readAction.sourceChapterId}/read-progress`,
method: 'PATCH',
data: {
'page': 1,
'completed': true
}
})

const response = await this.requestManager.schedule(request, 1)

if(response.status < 400) {
await actionQueue.discardChapterReadAction(readAction)
} else {
await actionQueue.retryChapterReadAction(readAction)
}
} catch(error) {
console.log(`Tracker action for manga id ${readAction.mangaId} failed with error:`)
console.log(error)
await actionQueue.retryChapterReadAction(readAction)
}
}
}
}
}

0 comments on commit 67f08c8

Please sign in to comment.