feat(mal): gated all MAL features and network logic behind authentication check

This commit is contained in:
paregi12 2026-03-12 20:18:16 +05:30
parent 433d3a21b9
commit 6e8b336e54
3 changed files with 12 additions and 8 deletions

View file

@ -47,6 +47,10 @@ class MalAuthService {
return this.token;
}
isAuthenticated(): boolean {
return this.getToken() !== null;
}
saveToken(token: MalToken) {
this.token = token;
mmkvStorage.setString(KEYS.ACCESS, token.accessToken);

View file

@ -188,7 +188,7 @@ export const MalSync = {
const isEnabled = mmkvStorage.getBoolean('mal_enabled') ?? true;
const isAutoUpdate = mmkvStorage.getBoolean('mal_auto_update') ?? true;
if (!isEnabled || !isAutoUpdate) {
if (!isEnabled || !isAutoUpdate || !MalAuth.isAuthenticated()) {
return;
}
@ -286,10 +286,10 @@ export const MalSync = {
*/
scrobbleDirect: async (malId: number, episodeNumber: number) => {
try {
// Respect user settings
// Respect user settings and login status
const isEnabled = mmkvStorage.getBoolean('mal_enabled') ?? true;
const isAutoUpdate = mmkvStorage.getBoolean('mal_auto_update') ?? true;
if (!isEnabled || !isAutoUpdate) return;
if (!isEnabled || !isAutoUpdate || !MalAuth.isAuthenticated()) return;
// Check current status
const currentInfo = await MalApiService.getMyListStatus(malId);
@ -325,6 +325,7 @@ export const MalSync = {
* Import MAL list items into local library
*/
syncMalToLibrary: async () => {
if (!MalAuth.isAuthenticated()) return false;
try {
let allItems: MalAnimeNode[] = [];
let offset = 0;
@ -366,6 +367,7 @@ export const MalSync = {
* Automatically adds MAL 'watching' items to the Nuvio Library
*/
syncMalWatchingToLibrary: async () => {
if (!MalAuth.isAuthenticated()) return;
try {
logger.log('[MalSync] Auto-syncing MAL watching items to library...');

View file

@ -219,10 +219,9 @@ class WatchedService {
}
// Sync to MAL
const malToken = MalAuth.getToken();
if (malToken) {
if (MalAuth.isAuthenticated()) {
MalSync.scrobbleEpisode(
title || '', // Use real title if provided for search fallback
title || 'Movie', // Use real title or generic fallback
1,
1,
'movie',
@ -300,8 +299,7 @@ class WatchedService {
}
// Sync to MAL
const malToken = MalAuth.getToken();
if (malToken && (showImdbId || malId || tmdbId)) {
if (MalAuth.isAuthenticated() && (showImdbId || malId || tmdbId)) {
// Strategy 0: Direct Match (if malId is provided)
let synced = false;
if (malId) {