Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const addPath = sounds => (dispatch) => {
const pathID = UUID.v4();
dispatch({
type: ADD_PATH,
sounds,
pathID,
});
// link new path to metronome ticks
dispatch(addPathEventListener(pathID));
};
async getTimelinesIntersectionPostIds(timelineId1, timelineId2) {
// zinterstore saves results to a key. so we have to
// create a temporary storage
let randomKey = mkKey(['timeline', timelineId1, 'random', uuid.v4()])
await this._getPostsTimelinesIntersection(randomKey, timelineId2, timelineId1)
let postIds = await this._getTimelinesIntersectionPosts(randomKey)
await this._deleteRecord(randomKey)
return postIds
}
const saveToLocalStorage = (sessionID, dataToSave) => (dispatch) => {
dispatch(displaySystemMessage('Saving session...'));
let itemID = sessionID;
if (!itemID) {
itemID = UUID.v4();
}
let existingSessions = localStorage.getItem(SAVED_SESSIONS_LOCAL_STORAGE_KEY);
if (!existingSessions) {
existingSessions = [];
} else {
existingSessions = JSON.parse(existingSessions);
}
let sessionName = dataToSave.session.name;
if (!sessionName) {
sessionName = `Untitled session #${existingSessions.length + 1}`;
}
const mutableDataToSave = Object.assign({}, dataToSave);
mutableDataToSave.session.name = sessionName;
mutableDataToSave.session.id = itemID;
const d = new Date();
const objectToSave = { id: itemID, lastModified: d.toISOString(), data: mutableDataToSave };
async createPost(payload) {
let postId = uuid.v4()
let key = mkKey(['post', postId])
let exists = await this._existsRecord(key)
if (exists !== 0) {
throw new Error("Already exists")
}
await this._createRecord(key, payload)
return postId
}
async createComment(payload) {
let commentId = uuid.v4()
let key = mkKey(['comment', commentId])
let exists = await this._existsRecord(key)
if (exists !== 0) {
throw new Error("Already exists")
}
await this._createRecord(key, payload)
return commentId
}
async createAttachment(payload) {
let attachmentId = uuid.v4()
let attachmentKey = mkKey(['attachment', attachmentId])
let exists = await this._existsRecord(attachmentKey)
if (exists !== 0) {
throw new Error("Already exists")
}
await this._createRecord(attachmentKey, payload)
return attachmentId
}
async createUser(payload) {
let userId = uuid.v4()
let username = payload.username
let email = payload.email
let userKey = mkKey(['user', userId])
let exists = await this._existsRecord(userKey)
if (exists !== 0) {
throw new Error("Already exists")
}
let promises = [
this._createUserUsernameIndex(userId, username),
this._createRecord(userKey, payload)
]
if (email && email.length > 0) {
promises.push(this.createUserEmailIndex(userId, email))
createTimeline(payload) {
let timelineId = uuid.v4()
let userId = payload.userId
return this._createTimeline(timelineId, userId, payload)
}
export const getSounds = (query, queryParams) => (dispatch, getStore) => {
dispatch(displaySystemMessage('Searching for sounds...'));
const queryID = UUID.v4();
dispatch(fetchRequest(queryID, query, queryParams));
const { maxResults, maxDuration, sorting } = queryParams;
submitQuery(query, maxResults, maxDuration, sorting).then(
(allPagesResults) => {
const sounds = reshapeReceivedSounds(allPagesResults, queryID);
const soundsFound = Object.keys(sounds).length;
if (!soundsFound) {
dispatch(displaySystemMessage('No sounds found', MESSAGE_STATUS.ERROR));
dispatch(fetchFailure('no sounds', queryID));
return;
}
const mapPosition = getStore().map;
dispatch(fetchSuccess(sounds, queryID, mapPosition));
dispatch(displaySystemMessage(`${soundsFound} sounds loaded, computing map`));
const tsne = getTrainedTsne(sounds, queryParams);
dispatch(computeTsneSolution(tsne, sounds, queryID));