logic for uploading and all with magic and all
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"apiKey": "AIzaSyAbTV9bb0TOtagzQMRMdXpSX5RhkS3z8NE",
|
||||
"authDomain": "nirvana-v3.firebaseapp.com",
|
||||
"projectId": "nirvana-v3",
|
||||
"storageBucket": "nirvana-v3.appspot.com",
|
||||
"storageBucket": "gs://nirvana-v3.appspot.com/",
|
||||
"messagingSenderId": "423533244953",
|
||||
"appId": "1:423533244953:web:b492f91669886c065db088",
|
||||
"measurementId": "G-0276T4D8NY",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { getDownloadURL, getStorage, ref, uploadBytes } from 'firebase/storage';
|
||||
|
||||
const storage = getStorage();
|
||||
|
||||
export const uploadAudioClip = async (uniqueFileName: string, blob: Blob) => {
|
||||
try {
|
||||
const audioClipsRef = ref(storage, `audioClips/${uniqueFileName}`);
|
||||
|
||||
// 'file' comes from the Blob or File API
|
||||
const snapshot = await uploadBytes(audioClipsRef, blob);
|
||||
|
||||
return await getDownloadURL(audioClipsRef);
|
||||
} catch (error) {
|
||||
console.warn('problem in uploading audio clip');
|
||||
|
||||
throw Error('problem in uploading audio clip');
|
||||
}
|
||||
};
|
||||
@@ -29,6 +29,7 @@ import Conversation, {
|
||||
MemberState,
|
||||
} from '@nirvana/core/src/models/conversation.model';
|
||||
import useAuth from '../providers/AuthProvider';
|
||||
import { AudioClip } from '@nirvana/core/src/models/content.model';
|
||||
|
||||
interface Document {
|
||||
id: string;
|
||||
@@ -60,6 +61,9 @@ const db = {
|
||||
user: (userId: string) => docPoint<User>(`users/${userId}`),
|
||||
conversations: collectionPoint<Conversation>(`conversations`),
|
||||
conversation: (conversationId: string) => docPoint<User>(`conversations/${conversationId}`),
|
||||
|
||||
conversationAudioClips: (conversationId: string) =>
|
||||
collectionPoint<AudioClip>(`conversations/${conversationId}/audioClips`),
|
||||
};
|
||||
|
||||
// enum COLLECTION {
|
||||
@@ -194,3 +198,13 @@ export const createGroupConversation = async (
|
||||
throw new Error('Error creating user');
|
||||
}
|
||||
};
|
||||
|
||||
export const sendAudioClipToConversation = async (audioClip: AudioClip, conversationId: string) => {
|
||||
try {
|
||||
await addDoc(db.conversationAudioClips(conversationId), audioClip);
|
||||
} catch (e) {
|
||||
console.error('Error creating user: ', e);
|
||||
|
||||
throw new Error('Error creating user');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user