projet
This commit is contained in:
20
services/discogsService.js
Normal file
20
services/discogsService.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const baseUrlsearch = 'https://api.discogs.com/database/search';
|
||||
const baseUrlrelease = 'https://api.discogs.com/releases/';
|
||||
const key = 'NWmMhlPAbPlVnaDqVGyX';
|
||||
const secret = 'hZPaoBiGiSwlCjARrbOICOpDuITwyJAm';
|
||||
const perPage = 100;
|
||||
|
||||
export async function discogsearch(query, type) {
|
||||
const url = `${baseUrlsearch}?q=${query}&type=${type}&per_page=${perPage}&key=${key}&secret=${secret}`;
|
||||
const response = await fetch(url);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
|
||||
export async function getReleaseDetails(releaseId) {
|
||||
const response = await fetch(`${baseUrlrelease}${releaseId}`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
window.getReleaseDetails = getReleaseDetails;
|
||||
window.discogsearch = discogsearch;
|
||||
84
services/firebaseService.js
Normal file
84
services/firebaseService.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// Firebase V9 ESM seulement
|
||||
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
|
||||
import {
|
||||
getAuth,
|
||||
createUserWithEmailAndPassword,
|
||||
signInWithEmailAndPassword,
|
||||
onAuthStateChanged,
|
||||
signOut
|
||||
} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js";
|
||||
|
||||
import {
|
||||
getFirestore,
|
||||
collection,
|
||||
addDoc,
|
||||
doc,
|
||||
setDoc
|
||||
} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore.js";
|
||||
|
||||
const firebaseConfig = {
|
||||
apiKey: "AIzaSyBXKB6AGbTN95lOLrIVpWrSIK_uL_C6GUA",
|
||||
authDomain: "music-app-riotjs.firebaseapp.com",
|
||||
projectId: "music-app-riotjs",
|
||||
storageBucket: "music-app-riotjs.firebasestorage.app",
|
||||
messagingSenderId: "483729603961",
|
||||
appId: "1:483729603961:web:122965ce7dbeb2e85103a8",
|
||||
measurementId: "G-18P6WCT80"
|
||||
};
|
||||
|
||||
const app = initializeApp(firebaseConfig);
|
||||
const auth = getAuth(app);
|
||||
const db = getFirestore(app);
|
||||
|
||||
export async function login(email, password) {
|
||||
await signInWithEmailAndPassword(auth, email, password);
|
||||
}
|
||||
|
||||
export async function sign(email, password) {
|
||||
const userCred = await createUserWithEmailAndPassword(auth, email, password);
|
||||
await adduserdata(userCred.user.email);
|
||||
}
|
||||
|
||||
export async function adduserdata(email_user) {
|
||||
await addDoc(collection(db, "users"), {
|
||||
email: email_user
|
||||
});
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
await signOut(auth);
|
||||
}
|
||||
|
||||
window.observeAuthState = function(callback) {
|
||||
onAuthStateChanged(auth, callback);
|
||||
};
|
||||
|
||||
export async function favorite(releaseId) {
|
||||
const user = auth.currentUser;
|
||||
if (!user) return;
|
||||
await addDoc(collection(db, "users", user.email, "favorites"), {
|
||||
id: releaseId
|
||||
});
|
||||
}
|
||||
|
||||
export async function getFavorites() {
|
||||
const user = auth.currentUser;
|
||||
if (!user) {
|
||||
console.warn("Aucun utilisateur connecté.");
|
||||
return [];
|
||||
}
|
||||
|
||||
const userDocRef = doc(db, "users", user.email);
|
||||
const favsCollection = collection(userDocRef, "favorites");
|
||||
|
||||
const snapshot = await getDocs(favsCollection);
|
||||
const favorites = snapshot.docs.map(doc => doc.data());
|
||||
|
||||
return favorites;
|
||||
}
|
||||
|
||||
window.login = login;
|
||||
window.sign = sign;
|
||||
window.logout = logout;
|
||||
window.favorite = favorite;
|
||||
window.getFavorites = getFavorites;
|
||||
Reference in New Issue
Block a user