upload & google sheet

main
reng 3 months ago
parent 410b1950d0
commit 44f5124396
  1. 6
      vite/public/cuelist_demo3.json
  2. 5
      vite/src-tauri/capabilities/default.json
  3. 11
      vite/src/pages/flow_free.jsx
  4. 29
      vite/src/util/backend.js
  5. 30
      vite/src/util/useUser.jsx

@ -47,8 +47,7 @@
"audioFile": "assets/ai/ai-01-2.mp3", "audioFile": "assets/ai/ai-01-2.mp3",
"nextcue": 4.1, "nextcue": 4.1,
"callback":"numpad", "callback":"numpad",
"numpad_type":"userid", "numpad_type":"userid"
"hint":"輸入兩位數號碼\n輸入完成送出,請按井字\n取消輸入,請按米字"
}, },
{ {
"id": 4.1, "id": 4.1,
@ -126,6 +125,7 @@
} }
}, },
"hint":"保留,請按1\n刪除,請按9\n確定,請按#", "hint":"保留,請按1\n刪除,請按9\n確定,請按#",
"hint_time": 21800,
"nextcue":5.4 "nextcue":5.4
}, },
{ {
@ -139,6 +139,7 @@
"callback":"numpad", "callback":"numpad",
"numpad_type":"password", "numpad_type":"password",
"hint":"請輸入四位數密碼\n確定輸入後,請按#", "hint":"請輸入四位數密碼\n確定輸入後,請按#",
"hint_time": 7800,
"default_password":"0000" "default_password":"0000"
}, },
{ {
@ -152,6 +153,7 @@
"callback":"numpad", "callback":"numpad",
"numpad_type":"password", "numpad_type":"password",
"hint":"請輸入四位數密碼\n確定輸入後,請按#", "hint":"請輸入四位數密碼\n確定輸入後,請按#",
"hint_time": 7900,
"default_password":"0000" "default_password":"0000"
}, },
{ {

@ -19,6 +19,11 @@
}, },
{ {
"url": "http://localhost:34800" "url": "http://localhost:34800"
},
{
"url": "http://**/"
},{
"url":"https://script.google.com/macros/s/AKfycbxpXbWhMdd4nv0KHhSzeFTKIV0tqsh-HBKCdlaOT34sh2vl1H5aoa36QnimhQg8I2aKRw/exec"
} }
] ]
}, },

@ -59,7 +59,7 @@ export function FreeFlow(){
const [padInput, setPadInput] = useState(null); const [padInput, setPadInput] = useState(null);
const { userId, setUserId, getFileId, setPassword, reset:resetUser, uploadHistory, setSummary, summary,setChoice,choice, getUploadFolder,getDataId } = useUser(); const { userId, setUserId, getFileId, setPassword, reset:resetUser, uploadHistory, setSummary, summary,setChoice,choice, getUploadFolder,getDataId, writeSheet } = useUser();
const refTimer=useRef(); const refTimer=useRef();
const refAudio=useRef(); const refAudio=useRef();
@ -326,6 +326,11 @@ export function FreeFlow(){
// if(cue.callback=='fade_in_light') refLight.current.fadeIn(); // Fade in light for conversation start // if(cue.callback=='fade_in_light') refLight.current.fadeIn(); // Fade in light for conversation start
// if(cue.callback=='fade_out_light') refLight.current.fadeOut(); // Fade out light for conversation end // if(cue.callback=='fade_out_light') refLight.current.fadeOut(); // Fade out light for conversation end
if(cue.hint!=null){
setTimeout(()=>{
sendOsc(OSC_ADDRESS.HINT, cue.hint); // Send OSC hint message
}, cue.hint_time);
}
if(cue.audioFile){ if(cue.audioFile){
playAudio(cue.audioFile); playAudio(cue.audioFile);
@ -382,7 +387,7 @@ export function FreeFlow(){
if(cue.hint!=null){ if(cue.hint!=null){
sendOsc(OSC_ADDRESS.HINT, cue.hint); // Send OSC hint message // sendOsc(OSC_ADDRESS.HINT, cue.hint); // Send OSC hint message
}else{ }else{
sendOsc(OSC_ADDRESS.HINT, ''); // Clear hint message sendOsc(OSC_ADDRESS.HINT, ''); // Clear hint message
} }
@ -426,7 +431,7 @@ export function FreeFlow(){
const default_image=!(user_input && user_input.content.trim() !== ''); const default_image=!(user_input && user_input.content.trim() !== '');
sendOsc(OSC_ADDRESS.EXPORT, `${getUploadFolder()}#${getDataId()}#${summary||''}#${getFileId(padInput)}#${choice||''}#${default_image?'default':'generated'}`); // Send OSC export message sendOsc(OSC_ADDRESS.EXPORT, `${getUploadFolder()}#${getDataId()}#${summary||''}#${getFileId(padInput)}#${choice||''}#${default_image?'default':'generated'}`); // Send OSC export message
writeSheet();
} }
useEffect(()=>{ useEffect(()=>{

@ -1,6 +1,7 @@
import { initializeApp } from "firebase/app"; import { initializeApp } from "firebase/app";
import { getFirestore, doc, setDoc } from "firebase/firestore"; import { getFirestore, doc, setDoc } from "firebase/firestore";
import { fetch } from '@tauri-apps/plugin-http';
const firebaseConfig = { const firebaseConfig = {
apiKey: "AIzaSyD1VzUKXt0JskwyfjfIAbdROzPNB3fTIw0", apiKey: "AIzaSyD1VzUKXt0JskwyfjfIAbdROzPNB3fTIw0",
@ -13,6 +14,7 @@ const firebaseConfig = {
}; };
const CollectionName="records"; const CollectionName="records";
const SheetId="14gbr7RkBXVVR9GwP1S9EHhoaRB5K44lzJBizrPosAGo"; // Replace with your Google Sheet ID
// Initialize Firebase // Initialize Firebase
const app = initializeApp(firebaseConfig); const app = initializeApp(firebaseConfig);
@ -33,3 +35,30 @@ export async function updateUser(id, data){
}; };
} }
export async function writeToGoogleSheet(date, session, userId, password){
if(!date || !session) {
console.error("Invalid data for writeToGoogleSheet");
return;
}
try{
await fetch(`https://script.google.com/macros/s/AKfycbxpXbWhMdd4nv0KHhSzeFTKIV0tqsh-HBKCdlaOT34sh2vl1H5aoa36QnimhQg8I2aKRw/exec`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"date":date,
"session":session,
"userId":userId,
"password":password
})
});
console.log("Data successfully sent to Google Sheet!");
}catch(error){
console.error("Error sending data to Google Sheet: ", error);
};
}

@ -1,6 +1,6 @@
import { createContext, useState, useEffect, useContext, use, useRef } from "react"; import { createContext, useState, useEffect, useContext, use, useRef } from "react";
import moment from "moment"; import moment from "moment";
import { updateUser } from "./backend"; import { updateUser, writeToGoogleSheet } from "./backend";
import { useData } from "./useData"; import { useData } from "./useData";
const userContext=createContext(); const userContext=createContext();
@ -27,7 +27,9 @@ export function UserProvider({children}) {
const {data}=useData(); const {data}=useData();
function getSessionId(){
return `${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}`;
}
function getFileId(pass){ function getFileId(pass){
if(!userId){ if(!userId){
if(data?.id){ if(data?.id){
@ -37,12 +39,12 @@ export function UserProvider({children}) {
}return `${password||pass||'0000'}_${userId}`; }return `${password||pass||'0000'}_${userId}`;
} }
function getDataId(){ function getDataId(){
if(!userId) return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}/testuser_${moment().format('hhmmss')}`; if(!userId) return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${getSessionId()}/testuser_${moment().format('hhmmss')}`;
return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}/${userId}`; return `${moment().format('YYYYMM')}/${moment().format("MMDD")}/${getSessionId()}/${userId}`;
} }
function getUploadFolder(){ function getUploadFolder(){
return `${moment().format("YYYYMM")}/${moment().format("MMDD")}/${SessionTime[sessionId]!=null? SessionTime[sessionId][0].replace(':',''):'no-session'}`; return `${moment().format("YYYYMM")}/${moment().format("MMDD")}/${getSessionId()}`;
} }
function reset(){ function reset(){
@ -68,6 +70,21 @@ export function UserProvider({children}) {
}); });
} }
function writeSheet(){
writeToGoogleSheet(
moment().format("YYYY/MM/DD"),
getSessionId(),
userId,
password
).then(() => {
console.log("Data written to Google Sheet successfully");
})
.catch((error) => {
console.error("Error writing data to Google Sheet:", error);
});
}
useEffect(()=>{ useEffect(()=>{
console.log("User ID changed:", password, sessionId, userId); console.log("User ID changed:", password, sessionId, userId);
@ -127,7 +144,8 @@ export function UserProvider({children}) {
reset, uploadHistory: saveHistory, setChoice, reset, uploadHistory: saveHistory, setChoice,
choice, choice,
setSummary, summary, getDataId, setSummary, summary, getDataId,
setPassword}}> setPassword,
writeSheet}}>
{children} {children}
</userContext.Provider> </userContext.Provider>
); );

Loading…
Cancel
Save