Downloading attachments from specific person's mail using appscript - gmail-api

I have tried to download the attachments by stating the required person's mail but downloading the attachments irrespective of the person's mail. Here is what I have tried.
function saveGmailtoDrive(){
var gmailThread = GmailApp.search('from:xyz#gmail.com subject:"AT TRACKER"');
const folderId ="1ifmrUCLLyvvnOlZi0gde6MWgMoowCZOL"
const searchQuery = "has:attachment"
const threads=GmailApp.search(searchQuery,0,10)
threads.forEach((thread) => {
const messages = thread.getMessages()
messages.forEach((message) => {
const attachments = message.getAttachments({
includeInlineImages:false,
includeAttachments:true
})
attachments.forEach((attachment) => {
Drive.Files.insert({
title:attachment.getName(),
mimeType:attachment.getContentType(),
parents:[{id:folderId}]
},
attachment.copyBlob()
)
})
})
})
}

Related

how can i delete multiples request at the same time using axios and an array of URL

im doing an app and the first code is working deleting a "task" in my API, but in my app each task have a checkbox input, so, i want to delete all the tasks that are checked.
i used this code to delete single task with a button.
const baseURLtasksId = `https://63cf2168e52f5878299ab5e2.mockapi.io/api/users/${userid}/tasks/${taskId}`
axios.delete(baseURLtasksId, { done: true }).then()
}
ArrayUrlById this is an array of all the URL's that are checked
const deleteAll = () => {
let ArrayUrlById = []
ArrayUrlById = isChecked.map((cId) => {
let arrayURL = `https://63cf2168e52f5878299ab5e2.mockapi.io/api/users/${userid}/tasks/${cId}`
return arrayURL
})
console.log(ArrayUrlById); // here i have an array of the URL
// i need to delete now multiples tasks, using an array of URL and sending {done:true} for each one
}
i tried with this code, but not working properly, beacuse never delete all of them, even in the console send all the delete request to the endpoint with a 200 status, but after i refresg the website, is not deleting all of them that are checked
const deleteAll = () => {
let ArrayUrlById = []
console.log('aqui');
ArrayUrlById = isChecked.map((c) => {
let arrayURL = `https://63cf2168e52f5878299ab5e2.mockapi.io/api/users/${userid}/tasks/${c}`
return arrayURL
})
console.log(ArrayUrlById);
const requests = ArrayUrlById.map(url => axios.delete(url));
axios.all(requests)
.then(responses => {
responses.forEach(response => console.log(response.data));
})
.catch(error => {
console.log(error);
})
}
enter image description here

Firebase v9 on react JS

I just want to check if i dont create an other chats on my firebase.
I query all my chat with this email and then, i check if the array contain the email i wanna tchat with but it doesn't work.
I'm using Firebase V9.
Anyone has an idea ?
function Sidebar() {
const [user] = useAuthState(auth);
const chatRef = collection(db, 'chats');
const qchatExist = query(chatRef, where('users', 'array-contains', user.email) );
const chatsSnapshot = getDocs(qchatExist);
const createChat = () => {
const input = prompt('Please enter a email adresse');
if(!input) return;
if (EmailValidator.validate(input) && !chatAlreadyExists(input) && input !== user.email ) {
console.log("valide");
addDoc(collection(db, 'chats'),
{
users: [user.email, input],
});
}
else {
console.log('invalide');
}
}
const chatAlreadyExists = (data) =>
!!chatsSnapshot?.docs.find(
chat =>
chat.data().users.find( (user) => user === data)?.length > 0
);
code
you probably wanna use Collection Group Queries.
so you can query across all the chats collection at once.
https://firebase.google.com/docs/firestore/query-data/queries#:~:text=We%20can%20use,across%20all%20cities%3A
const users = query(collectionGroup(db, 'users'), where('email', '==', 'example#hoge.com'));
and make sure you create indexes for the query.
Before using a collection group query, you must create an index that supports your collection group query. You can create an index through an error message, the console, or the Firebase CLI.

How to keep user joined to their multiple rooms socket.io

I am completely new to socket.io and I have been stuck on this problem for so many days. I can't find any deep youtube vidoes on this topic either. What I am trying to do is, I am creating a chat app. As soon as you log in you will see all the groups and you can join these groups. Let's assume that user has joined 3 groups. As soon as that user logs in I would like to join that user to those three groups so that he would get messages when there is any. How can that be done??
This is what I have done so far,
Front-end
when message is sent
socket.emit("message", { name, message, room: selectedGroup.name });
socket.emit("join-group", { name, room: group.name });
socket.on("message", ({ name, message, room }) => {
const update = { ...group };
update.messages.push({ sender: name, message });
setSelectedGroup(update);
});
Back-End
io.on("connection", (socket) => {
socket.on("join-group", ({ name, room }) => {
socket.join(room);
});
socket.on("message", ({ name, message, room }) => {
socket.join(room);
io.to(room).emit("message", { name, message, room });
});
});
my main language is not English, so I apologize for that
There is an adapter in the io object that can access all active rooms inside, and if you want to have access to all of them when the user logs in, you must use these commands in onConnection
However, versions 2,3,4 are different in this regard.
https://socket.io/docs/v4/adapter/
From the top right you can find the version you want
const socketio = require("socket.io");
const server = http.createServer(app);
const io = socketio(server);
const activeRooms(io)=> {
const arr = Array.from(io.sockets.adapter.rooms);
// [['room1', Set(2)], ['room2', Set(2)]]
const filtered = arr.filter(room => !room[1].has(room[0]))
// ['room1', 'room2']
const res = filtered.map(i => i[0]);
return res;
}
const rooms = activeRooms()
if (rooms) {
rooms.forEach((element) => {
socket.join(element.toString());
});
socket.join(socket.username);
}
}

ReactJS: STOMP subscription to multiple topics

My React code creates a WebSocket connection to our company's ActiveMQ 5.15.5 server, and then subscribes to the following two topics: salary and decoding. The problem is that the code is only able to subscribe to one of the topics. It cannot subscribe to both.
const client = window.Stomp.client(`ws://${ipAddress}:61614`, 'aj6.stomp');
const headers = { id: 'username' };
client.debug = null;
client.connect('user', 'pass', () => {
client.subscribe(
'/topic/salary', //BREAKPOINT was set here
message => {
const body = JSON.parse(message.body);
if (body && body.pcId) {
salaries[body.pcId] = body;
setState({ salaries});
}
},
headers,
);
client.subscribe(
'/topic/decoding', //BREAKPOINT was set here
message => {
const newBody = JSON.parse(message.body);
if (newBody && newBody.PcID) {
consoleMessage[newBody.PcID] = newBody;
setState({ consoleMessage });
}
},
headers,
);
});
So in the code above I put a break-point at client.subscribe('/topic/decoding... and client.subscribe('/topic/salary.... I saw that it only subscribes to /topic/decoding but not /topic/salary.
Does anyone know how I can fix this issue so that it subscribes to both topics?
From Stomp documentation:
Since a single connection can have multiple open subscriptions with a server, an id header MUST be included in the frame to uniquely identify the subscription. The id header allows the client and server to relate subsequent MESSAGE or UNSUBSCRIBE frames to the original subscription.
Within the same connection, different subscriptions MUST use different subscription identifiers.
Stomp API definition:
subscribe(destination, callback, headers = {})
So for my understanding, You can't have the same username id for both of your subscriptions
Try creating 2 clients, e.g.:
const salaryClient = window.Stomp.client(`ws://${ipAddress}:61614`, 'aj6.stomp');
const salaryHeaders = { id: 'salary' };
salaryClient.debug = null;
salaryClient.connect('user', 'pass', () => {
salaryClient.subscribe(
'/topic/salary',
message => {
const body = JSON.parse(message.body);
if (body && body.pcId) {
salaries[body.pcId] = body;
setState({ salaries});
}
},
salaryHeaders,
);
});
const decodingClient = window.Stomp.client(`ws://${ipAddress}:61614`, 'aj7.stomp');
const decodingHeaders = { id: 'decoding' };
decodingClient.debug = null;
decodingClient.connect('user', 'pass', () => {
decodingClient.subscribe(
'/topic/decoding',
message => {
const newBody = JSON.parse(message.body);
if (newBody && newBody.PcID) {
consoleMessage[newBody.PcID] = newBody;
setState({ consoleMessage });
}
},
decodingHeaders,
);
});

FS access api & React: duplicate entries

I'm trying to build a movie dashboard (something like Plex); the user selects a folder and all the movies he has in the folder show up. The use of the new File System Access API allows me to create file handlers on the fly and be able to display movies using the browser video player.
The problem I'm facing is with duplicated entries, for instance "Ghostbusters" (can't really understand why, but that's the only one causing the issue)
This is the basic implementation of the file system:
try {
const folderHandle = await window.showDirectoryPicker();
const addedFilms = [];
history.push('/list');
// const entries = await folderHandle.values()
const entries = await folderHandle.values();
for await (const entry of entries) {
const movie = await readMoviesonDisk(folderHandle, entry);
console.log(addedFilms);
if (addedFilms.includes(entry.name)) continue;
addedFilms.push(entry.name);
setMovies((movies) => [...movies, movie]);
}
} catch (error) {
alert('Alert from reading files: ' + error);
}
setMovies just sets a Context with a movies array and readMoviesOnDisk is the following:
const readMoviesonDisk = async (folderHandle, entry) => {
if (entry.kind === 'file' && entry.name.endsWith('.mp4')) {
const path = await folderHandle.resolve(entry);
const handle = await folderHandle.getFileHandle(path);
const movie = await getMovie(entry.name);
if (movie) {
return { ...movie.data, file: handle, name: entry.name };
}
const movieData = await searchMovie(entry.name);
if (movieData) {
const actualData = await getMovieDetails(movieData.id);
if (actualData !== undefined) {
await insertMovie(entry.name, actualData, handle);
} else {
await insertMovie(entry.name, actualData, handle);
}
return { ...actualData, file: handle, name: entry.name };
}
return { name: entry.name, file: handle };
}
};
searchMovie and insertMovie only interact with IndexedDB to store movie info for offline use. getMovieDetails does API calls to TMDB to get movie info.
The key I use for displaying the movies is their TMDB id. Ghostbusters' id is "620".
Can anyone help me?
Without additional background it seems impossible to answer this properly. Can you iterate over all files in the folder and just log the names and kinds? This should work and show no duplicate entries.
const dirHandle = await window.showDirectoryPicker();
for await (const entry of dirHandle.values()) {
console.log(entry.kind, entry.name);
}

Resources