PageSourceSearch

https://canticosliturgicos.com.br/app/js/data/musicService.js?v=4415

js canticosliturgicos.com.br collected 2026-10-02 01:17:47 UTC 3,116 bytes, 149 lines download raw bytes

1//const musics = JSON.parse(localStorage.getItem("musics"));
2
3function displayRecordCount(count) {
4    console.log(`✔️ Total de registros recuperados: ${count}`);
5    // Aqui você pode adicionar lógica para exibir a contagem em sua interface de usuário ou fazer qualquer outra coisa que desejar.
6}
7
8async function getMusics() {
9   // tenta IndexedDB primeiro
10   try {
11      const musics =
12         await getMusicsFromIndexedDB();
13      if (musics && musics.length > 0) {
14         console.log(
15            "🎵 músicas carregadas do IndexedDB"
16         );
17         return musics;
18      }
19   } catch (e) {
20      console.warn(
21         "❌ IndexedDB indisponível"
22      );
23   }
24
25   // fallback API
26   const response = await fetch(
27      request + `musics_DB.php`
28   );
29
30   const musics =
31      await response.json();
32   console.log(
33      "🌐 músicas carregadas da API"
34   );
35   return musics;
36   console.log(musics)
37}
38
39async function getMusic(id) {
40   // APP → IndexedDB
41   try {
42      const musics =
43         await getMusicsFromIndexedDB();
44      if (musics?.length > 0) {
45         return musics.find(
46            m => Number(m.id) === Number(id)
47         );
48      }
49
50   } catch(e) {
51      console.warn(
52         "❌ IndexedDB indisponível"
53      );
54   }
55
56   // WEB → API específica
57   const response = await fetch(
58      request + 'music_DB.php?id=' + id
59   );
60   return await response.json();
61}
62
63
64async function getMusicsFromIndexedDB() {
65
66   return new Promise((resolve, reject) => {
67
68      const requestM =
69         indexedDB.open('MusicsAllApp', 1);
70
71      // CRIA STORE SE NÃO EXISTIR
72      requestM.onupgradeneeded = function(event) {
73
74         const db = event.target.result;
75
76         if (
77            !db.objectStoreNames.contains('musics')
78         ) {
79
80            db.createObjectStore('musics', {
81               keyPath: 'id'
82            });
83
84         }
85
86      };
87
88      requestM.onsuccess = function(event) {
89
90         const db = event.target.result;
91
92         // segurança extra
93         if (
94            !db.objectStoreNames.contains('musics')
95         ) {
96
97            db.close();
98
99            resolve([]);
100
101            return;
102
103         }
104
105         const transaction =
106            db.transaction('musics', 'readonly');
107
108         const objectStore =
109            transaction.objectStore('musics');
110
111         const musics = [];
112
113         const cursorRequest =
114            objectStore.openCursor();
115
116         cursorRequest.onsuccess = function(event) {
117
118            const cursor =
119               event.target.result;
120
121            if (cursor) {
122
123               musics.push(cursor.value);
124
125               cursor.continue();
126
127            } else {
128
129               musics.sort((a, b) =>
130                  a.name.localeCompare(b.name)
131               );
132
133               db.close();
134
135               resolve(musics);
136
137            }
138
139         };
140
141         cursorRequest.onerror = reject;
142
143      };
144
145      requestM.onerror = reject;
146
147   });
148
149}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.