modificato deploy verso contabo

This commit is contained in:
David Frassi
2026-06-17 01:04:27 +02:00
parent 2d23dcae83
commit 97a11d5074
24 changed files with 1063 additions and 64 deletions
+170 -12
View File
@@ -278,11 +278,12 @@ export class HomePage implements OnDestroy {
const comunitaIds = this.comunitaService.comunitaCantiIds();
if (comunitaCode && this.comunitaService.isFilterActive()) {
// Base is standard canti + my canti + community custom canti + remote custom canti
// Base is standard canti + my canti + community custom canti + remote custom canti + remote share canti
list = [
...this.cantiService.canti(),
...this.myCantiService.myCanti(),
...this.playlistService.remoteCustomSongs(),
...this.playlistService.remoteShareCanti(),
...this.comunitaService.comunitaCantiPersonali()
];
@@ -316,11 +317,12 @@ export class HomePage implements OnDestroy {
return numA - numB;
});
} else {
// General context: only standard canti + my canti + remote custom canti
// General context: only standard canti + my canti + remote custom canti + remote share canti
list = [
...this.cantiService.canti(),
...this.myCantiService.myCanti(),
...this.playlistService.remoteCustomSongs()
...this.playlistService.remoteCustomSongs(),
...this.playlistService.remoteShareCanti()
];
}
@@ -488,9 +490,21 @@ export class HomePage implements OnDestroy {
if (this.settingsService.isVersionCheckComplete() && !queryParamsSubscribed) {
queryParamsSubscribed = true;
this.queryParamsSubscription = this.route.queryParams.subscribe(params => {
if (params['id']) {
const idVal = params['id'];
this.router.navigate([], { queryParams: { id: null, t: null }, queryParamsHandling: 'merge', replaceUrl: true }).then(() => {
this.goToCanto(idVal);
});
}
if (params['import']) {
this.handleImport(params['import']);
}
if (params['import-canto']) {
this.handleImportCanto(params['import-canto']);
}
if (params['song-uid'] && params['song-id']) {
this.handleRemoteSongImport(params['song-uid'], params['song-id']);
}
if (params['playlist-uid']) {
this.handleRemotePlaylistImport(params['playlist-uid'], params['playlist-id']);
}
@@ -508,7 +522,7 @@ export class HomePage implements OnDestroy {
if (versionReady && lastPl && !hasAutoActivatedPlaylist) {
const params = this.route.snapshot.queryParams;
if (!params['id'] && !params['import'] && !params['playlist-uid'] && !params['restore-uid']) {
if (!params['id'] && !params['import'] && !params['playlist-uid'] && !params['restore-uid'] && !params['song-uid'] && !params['import-canto']) {
hasAutoActivatedPlaylist = true;
this.selectPlaylist(lastPl);
this.activeFilterType.set('playlist');
@@ -581,7 +595,8 @@ export class HomePage implements OnDestroy {
async handleImport(base64: string) {
try {
const decoded = decodeURIComponent(escape(atob(base64)));
const base64Safe = base64.replace(/ /g, '+');
const decoded = decodeURIComponent(escape(atob(base64Safe)));
const json = JSON.parse(decoded);
if (json && json.comunitaCode) {
@@ -630,11 +645,12 @@ export class HomePage implements OnDestroy {
}
}
const openFirst = this.route.snapshot.queryParams['openFirst'] === '1';
if (this.playlistService.processImportJson(json)) {
this.limit.set(50); // Mostra più canti inizialmente per le playlist speciali
this.activeFilterType.set('playlist');
await this.router.navigate([], { queryParams: { import: null }, queryParamsHandling: 'merge', replaceUrl: true });
if (json.ids && json.ids.length > 0) {
await this.router.navigate([], { queryParams: { import: null, openFirst: null }, queryParamsHandling: 'merge', replaceUrl: true });
if (openFirst && json.ids && json.ids.length > 0) {
this.goToCanto(json.ids[0]);
}
}
@@ -650,6 +666,117 @@ export class HomePage implements OnDestroy {
}
}
async handleImportCanto(base64: string) {
try {
const base64Safe = base64.replace(/ /g, '+');
const decoded = decodeURIComponent(escape(atob(base64Safe)));
const json = JSON.parse(decoded);
if (json && json.cantoShare && json.titolo) {
const id_canti = Date.now();
const id = `remote_share_${id_canti}`;
const canto: any = {
id: id,
id_canti: id_canti,
titolo: json.titolo,
autore: json.autore || '',
testo: json.testo || '',
accordi: json.accordi || '',
link_youtube: json.link_youtube || '',
id_momenti: json.id_momenti || [],
nonValidato: true
};
await this.playlistService.saveRemoteShareCanto(canto);
const toast = await this.toastCtrl.create({
message: `Canto "${canto.titolo}" importato nei brani remoti non validati!`,
duration: 3000,
color: 'success',
position: 'bottom'
});
await toast.present();
await this.router.navigate([], { queryParams: { 'import-canto': null }, queryParamsHandling: 'merge', replaceUrl: true });
this.goToCanto(canto.id);
}
} catch (e) {
console.error('Failed to import canto', e);
const toast = await this.toastCtrl.create({
message: 'Errore durante l\'importazione del canto.',
duration: 3000,
color: 'danger',
position: 'bottom'
});
await toast.present();
}
}
async handleRemoteSongImport(uid: string, songId: string) {
const loading = await this.loadingCtrl.create({
message: 'Scaricamento canto da remoto...'
});
await loading.present();
try {
const response = await fetch(`https://api.canticristiani.it/${uid}.json?cb=${Date.now()}`, { cache: 'no-store' });
if (!response.ok) {
throw new Error(`Risposta del server non valida: ${response.status}`);
}
const remoteJson = await response.json();
if (Array.isArray(remoteJson)) {
const item = remoteJson.find((x: any) =>
Number(x.id_canti) === Number(songId) &&
(!x.momenti || (!x.momenti.includes('Playlist') && !x.momenti.includes('UserMetadata')))
);
if (!item) {
throw new Error('Canto non trovato nel profilo remoto.');
}
const id = `remote_share_${item.id_canti}`;
const canto: any = {
id: id,
id_canti: Number(item.id_canti),
titolo: item.titolo || 'Senza Titolo',
autore: item.autore || '',
testo: item.testo || '',
accordi: item.accordi || (item.testo?.includes('[') ? item.testo : undefined),
link_youtube: item.link_youtube || '',
id_momenti: item.momenti?.map((m: any) => Number(m)).filter((m: any) => !isNaN(m)) || [],
nonValidato: true
};
await this.playlistService.saveRemoteShareCanto(canto);
const toast = await this.toastCtrl.create({
message: `Canto "${canto.titolo}" importato nei brani remoti non validati!`,
duration: 3000,
color: 'success',
position: 'bottom'
});
await toast.present();
await this.router.navigate([], { queryParams: { 'song-uid': null, 'song-id': null }, queryParamsHandling: 'merge', replaceUrl: true });
this.goToCanto(canto.id);
} else {
throw new Error('Formato dati non valido.');
}
} catch (err: any) {
console.error('Failed to import remote song:', err);
const alert = await this.alertCtrl.create({
header: 'Errore Importazione',
message: 'Impossibile scaricare il canto da remoto. Controlla la connessione o il link.',
buttons: ['OK']
});
await alert.present();
await this.router.navigate([], { queryParams: { 'song-uid': null, 'song-id': null }, queryParamsHandling: 'merge', replaceUrl: true });
} finally {
await loading.dismiss();
}
}
async handleRemotePlaylistImport(uid: string, pid?: string) {
const loading = await this.loadingCtrl.create({
message: 'Scaricamento playlist da remoto...'
@@ -657,6 +784,7 @@ export class HomePage implements OnDestroy {
await loading.present();
let hasNavigatedToCanto = false;
const openFirst = this.route.snapshot.queryParams['openFirst'] === '1';
try {
const response = await fetch(`https://api.canticristiani.it/${uid}.json?cb=${Date.now()}`, { cache: 'no-store' });
if (!response.ok) {
@@ -672,7 +800,9 @@ export class HomePage implements OnDestroy {
id_canti: Number(item.id_canti),
titolo: item.titolo,
testo: item.testo,
accordi: item.testo?.includes('[') ? item.testo : undefined,
accordi: item.accordi || (item.testo?.includes('[') ? item.testo : undefined),
autore: item.autore || '',
link_youtube: item.link_youtube || '',
id_momenti: item.momenti?.map((m: any) => Number(m)).filter((m: any) => !isNaN(m)) || []
}));
@@ -731,8 +861,10 @@ export class HomePage implements OnDestroy {
if (selectedPl.ids && selectedPl.ids.length > 0) {
hasNavigatedToCanto = true;
await this.router.navigate([], { queryParams: { 'playlist-uid': null, 'playlist-id': null }, queryParamsHandling: 'merge', replaceUrl: true });
this.goToCanto(selectedPl.ids[0]);
await this.router.navigate([], { queryParams: { 'playlist-uid': null, 'playlist-id': null, 'openFirst': null }, queryParamsHandling: 'merge', replaceUrl: true });
if (openFirst) {
this.goToCanto(selectedPl.ids[0]);
}
}
} else {
throw new Error('Formato dati non valido.');
@@ -748,7 +880,7 @@ export class HomePage implements OnDestroy {
await alert.present();
} finally {
if (!hasNavigatedToCanto) {
this.router.navigate([], { queryParams: { 'playlist-uid': null, 'playlist-id': null }, queryParamsHandling: 'merge' });
this.router.navigate([], { queryParams: { 'playlist-uid': null, 'playlist-id': null, 'openFirst': null }, queryParamsHandling: 'merge', replaceUrl: true });
}
}
}
@@ -787,7 +919,9 @@ export class HomePage implements OnDestroy {
id_canti: Number(item.id_canti),
titolo: item.titolo || 'Senza Titolo',
testo: item.testo || '',
accordi: item.testo?.includes('[') ? item.testo : undefined,
accordi: item.accordi || (item.testo?.includes('[') ? item.testo : undefined),
autore: item.autore || '',
link_youtube: item.link_youtube || '',
id_momenti: item.momenti?.map((m: any) => Number(m)).filter((m: any) => !isNaN(m)) || []
}));
@@ -898,6 +1032,7 @@ export class HomePage implements OnDestroy {
...this.cantiService.canti(),
...this.myCantiService.myCanti(),
...this.playlistService.remoteCustomSongs(),
...this.playlistService.remoteShareCanti(),
...this.comunitaService.comunitaCantiPersonali()
].find(c => c.id === id || String(c.id_canti) === id);
}
@@ -1401,6 +1536,29 @@ export class HomePage implements OnDestroy {
}
}
if (data.includes('import-canto=')) {
try {
let base64 = '';
if (data.includes('?import-canto=')) {
base64 = data.split('?import-canto=')[1];
} else if (data.includes('&import-canto=')) {
base64 = data.split('&import-canto=')[1];
}
if (base64.includes('&')) {
base64 = base64.split('&')[0];
}
if (base64.includes('#')) {
base64 = base64.split('#')[0];
}
this.handleImportCanto(base64);
return;
} catch (e) {
console.error('Failed to parse scanned canto link', e);
}
}
if (data.includes('import=')) {
try {
let base64 = '';