web: use monograph stats api

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-11-07 10:22:52 +05:00
parent a6541b9731
commit 3e87e2ea5a
5 changed files with 42 additions and 7 deletions

View File

@@ -37,6 +37,9 @@ type EncryptedMonograph = MonographApiRequestBase & {
type MonographApiRequest = (UnencryptedMonograph | EncryptedMonograph) & {
userId: string;
};
export type MonographStats = {
viewCount: number;
};
export type PublishOptions = { password?: string; selfDestruct?: boolean };
export class Monographs {
@@ -187,4 +190,17 @@ export class Monographs {
if (!monographPasswordsKey) return "";
return this.db.storage().decrypt(monographPasswordsKey, password);
}
async stats(monographId: string) {
const token = await this.db.tokenManager.getAccessToken();
const { viewCount } = (await http.get(
`${Constants.API_HOST}/monographs/${monographId}/stats`,
token
)) as MonographStats;
await this.db.monographsCollection.add({
id: monographId,
viewCount
});
return { viewCount };
}
}