refactor: Organize Project Structure (#1211)

* refactor: Organize Project Structure

* fix

* fix

* rm security

* fix
This commit is contained in:
pa
2025-04-18 15:04:03 +09:00
committed by GitHub
parent 59d3ead781
commit 6bda44be52
106 changed files with 172 additions and 165 deletions

174
src/api/avatar.js Normal file
View File

@@ -0,0 +1,174 @@
// #region | API: Avatar
const avatarReq = {
/**
* @param {{ avatarId: string }} params
* @returns {Promise<{json: any, params}>}
*/
getAvatar(params) {
return window.API.call(`avatars/${params.avatarId}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR', args);
return args;
});
},
/**
* @typedef {{
* n: number,
* offset: number,
* search: string,
* userId: string,
* user: 'me' | 'friends'
* sort: 'created' | 'updated' | 'order' | '_created_at' | '_updated_at',
* order: 'ascending' | 'descending',
* releaseStatus: 'public' | 'private' | 'hidden' | 'all',
* featured: boolean
* }} GetAvatarsParameter
*/
/**
*
* @param {GetAvatarsParameter} params
* @returns {Promise<{json: any, params}>}
*/
getAvatars(params) {
return window.API.call('avatars', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR:LIST', args);
return args;
});
},
/**
* @param {{ id: string, releaseStatus: 'public' | 'private' }} params
* @returns {Promise<{json: any, params}>}
*/
saveAvatar(params) {
return window.API.call(`avatars/${params.id}`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR:SAVE', args);
return args;
});
},
/**
* @param {{avatarId: string }} params
* @returns {Promise<{json: any, params}>}
*/
selectAvatar(params) {
return window.API.call(`avatars/${params.avatarId}/select`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR:SELECT', args);
return args;
});
},
/**
* @param {{ avatarId: string }} params
* @return { Promise<{json: any, params}> }
*/
selectFallbackAvatar(params) {
return window.API.call(`avatars/${params.avatarId}/selectfallback`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR:SELECT', args);
return args;
});
},
/**
* @param {{ avatarId: string }} params
* @return { Promise<{json: any, params}> }
*/
deleteAvatar(params) {
return window.API.call(`avatars/${params.avatarId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR:DELETE', args);
return args;
});
},
/**
* @param {{ avatarId: string }} params
* @returns {Promise<{json: any, params}>}
*/
createImposter(params) {
return window.API.call(`avatars/${params.avatarId}/impostor/enqueue`, {
method: 'POST'
}).then((json) => {
const args = {
json,
params
};
// window.API.$emit('AVATAR:IMPOSTER:CREATE', args);
return args;
});
},
/**
* @param {{ avatarId: string }} params
* @returns {Promise<{json: T, params}>}
*/
deleteImposter(params) {
return window.API.call(`avatars/${params.avatarId}/impostor`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
// window.API.$emit('AVATAR:IMPOSTER:DELETE', args);
return args;
});
},
/**
* @returns {Promise<{json: any, params}>}
*/
getAvailableAvatarStyles() {
return window.API.call('avatarStyles', {
method: 'GET'
}).then((json) => {
const args = {
json
};
// window.API.$emit('AVATAR:STYLES', args);
return args;
});
}
};
// #endregion
export default avatarReq;

View File

@@ -0,0 +1,60 @@
// #region | API: AvatarModeration
const avatarModerationReq = {
getAvatarModerations() {
return window.API.call('auth/user/avatarmoderations', {
method: 'GET'
}).then((json) => {
const args = {
json
};
// window.API.$emit('AVATAR-MODERATION:LIST', args);
return args;
});
},
/**
* @param {{ avatarModerationType: string, targetAvatarId: string }} params
* @return { Promise<{json: any, params}> }
*/
sendAvatarModeration(params) {
return window.API.call('auth/user/avatarmoderations', {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
// window.API.$emit('AVATAR-MODERATION', args);
return args;
});
},
/**
* @param {{ avatarModerationType: string, targetAvatarId: string }} params
* @return { Promise<{json: any, params}> }
*/
deleteAvatarModeration(params) {
return window.API.call(
`auth/user/avatarmoderations?targetAvatarId=${encodeURIComponent(
params.targetAvatarId
)}&avatarModerationType=${encodeURIComponent(
params.avatarModerationType
)}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATAR-MODERATION:DELETE', args);
return args;
});
}
};
// #endregion
export default avatarModerationReq;

187
src/api/favorite.js Normal file
View File

@@ -0,0 +1,187 @@
// #region | API: Favorite
const favoriteReq = {
getFavoriteLimits() {
return window.API.call('auth/user/favoritelimits', {
method: 'GET'
}).then((json) => {
const args = {
json
};
window.API.$emit('FAVORITE:LIMITS', args);
return args;
});
},
/**
* @param {{
* n: number,
* offset: number,
* type: string,
* tag: string
* }} params
* @return { Promise<{json: any, params}> }
*/
getFavorites(params) {
return window.API.call('favorites', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:LIST', args);
return args;
});
},
/**
* @param {{
* type: string,
* favoriteId: string (objectId),
* tags: string
* }} params
* @return { Promise<{json: any, params}> }
*/
addFavorite(params) {
return window.API.call('favorites', {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:ADD', args);
return args;
});
},
/**
* @param {{ objectId: string }} params
* @return { Promise<{json: any, params}> }
*/
deleteFavorite(params) {
return window.API.call(`favorites/${params.objectId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:DELETE', args);
return args;
});
},
/**
* @param {{ n: number, offset: number, type: string }} params
* @return { Promise<{json: any, params}> }
*/
getFavoriteGroups(params) {
return window.API.call('favorite/groups', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:GROUP:LIST', args);
return args;
});
},
/**
*
* @param {{ type: string, group: string, displayName: string, visibility: string }} params group is a name
* @return { Promise<{json: any, params}> }
*/
saveFavoriteGroup(params) {
return window.API.call(
`favorite/group/${params.type}/${params.group}/${window.API.currentUser.id}`,
{
method: 'PUT',
params
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:GROUP:SAVE', args);
return args;
});
},
/**
* @param {{
* type: string,
* group: string (name)
* }} params
* @return { Promise<{json: any, params}> }
*/
clearFavoriteGroup(params) {
return window.API.call(
`favorite/group/${params.type}/${params.group}/${window.API.currentUser.id}`,
{
method: 'DELETE',
params
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:GROUP:CLEAR', args);
return args;
});
},
/**
* @param {{
* n: number,
* offset: number
* }} params
* @return { Promise<{json: any, params}> }
*/
getFavoriteWorlds(params) {
return window.API.call('worlds/favorites', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:WORLD:LIST', args);
return args;
});
},
/**
* @param {{
* n: number,
* offset: number
* }} params
* @return { Promise<{json: any, params}> }
*/
getFavoriteAvatars(params) {
return window.API.call('avatars/favorites', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FAVORITE:AVATAR:LIST', args);
return args;
});
}
};
// #endregion
export default favoriteReq;

111
src/api/friend.js Normal file
View File

@@ -0,0 +1,111 @@
// #region | API: Friend
const friendReq = {
/**
* Fetch friends of current user.
* @param {{ n: number, offset: number, offline: boolean }} params
* @returns {Promise<{json: any, params}>}
*/
getFriends(params) {
return window.API.call('auth/user/friends', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FRIEND:LIST', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @returns {Promise<{json: T, params}>}
*/
sendFriendRequest(params) {
return window.API.call(`user/${params.userId}/friendRequest`, {
method: 'POST'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FRIEND:REQUEST', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @returns {Promise<{json: any, params}>}
*/
cancelFriendRequest(params) {
return window.API.call(`user/${params.userId}/friendRequest`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FRIEND:REQUEST:CANCEL', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @returns {Promise<{json: any, params}>}
*/
deleteFriend(params) {
return window.API.call(`auth/user/friends/${params.userId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FRIEND:DELETE', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @returns {Promise<{json: any, params}>}
*/
getFriendStatus(params) {
return window.API.call(`user/${params.userId}/friendStatus`, {
method: 'GET'
}).then((json) => {
console.log('getFriendStatus', json);
const args = {
json,
params
};
window.API.$emit('FRIEND:STATUS', args);
return args;
});
},
// ------------------- need to test -------------------
deleteHiddenFriendRequest(params, userId) {
return window.API.call(`user/${userId}/friendRequest`, {
method: 'DELETE',
params
}).then((json) => {
const args = {
json,
params,
userId
};
window.API.$emit('NOTIFICATION:HIDE', args);
return args;
});
}
};
// #endregion
export default friendReq;

773
src/api/group.js Normal file
View File

@@ -0,0 +1,773 @@
const groupReq = {
/**
* @param {string} groupId
* @param {{isRepresenting: bool}} params
* @returns
*/
setGroupRepresentation(groupId, params) {
return window.API.call(`groups/${groupId}/representation`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
groupId,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
cancelGroupRequest(params) {
return window.API.call(`groups/${params.groupId}/requests`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string, postId: string }} params
* @return { Promise<{json: any, params}> }
*/
deleteGroupPost(params) {
return window.API.call(
`groups/${params.groupId}/posts/${params.postId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
*/
getGroup(params) {
return window.API.call(`groups/${params.groupId}`, {
method: 'GET',
params: {
includeRoles: params.includeRoles || false
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @return { Promise<{json: any, params}> }
*/
getRepresentedGroup(params) {
return window.API.call(`users/${params.userId}/groups/represented`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:REPRESENTED', args);
return args;
});
},
/**
* @param {{ userId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroups(params) {
return window.API.call(`users/${params.userId}/groups`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:LIST', args);
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
joinGroup(params) {
return window.API.call(`groups/${params.groupId}/join`, {
method: 'POST'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:JOIN', args);
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
leaveGroup(params) {
return window.API.call(`groups/${params.groupId}/leave`, {
method: 'POST'
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ query: string }} params
* @return { Promise<{json: any, params}> }
*/
groupStrictsearch(params) {
return window.API.call(`groups/strictsearch`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
userId: string,
groupId: string,
params: {
visibility: string,
isSubscribedToAnnouncements: bool,
managerNotes: string
}
*/
setGroupMemberProps(userId, groupId, params) {
return window.API.call(`groups/${groupId}/members/${userId}`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
userId,
groupId,
params
};
window.API.$emit('GROUP:MEMBER:PROPS', args);
return args;
});
},
/**
* @param {{
* userId: string,
* groupId: string,
* roleId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
addGroupMemberRole(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}/roles/${params.roleId}`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
// window.API.$emit('GROUP:MEMBER:ROLE:CHANGE', args);
return args;
});
},
/**
* @param {{
* userId: string,
* groupId: string,
* roleId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
removeGroupMemberRole(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}/roles/${params.roleId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
// window.API.$emit('GROUP:MEMBER:ROLE:CHANGE', args);
return args;
});
},
getGroupPermissions(params) {
return window.API.call(`users/${params.userId}/groups/permissions`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:PERMISSIONS', args);
return args;
});
},
/**
* @param {{
groupId: string,
n: number,
offset: number
}} params
* @return { Promise<{json: any, params}> }
*/
getGroupPosts(params) {
return window.API.call(`groups/${params.groupId}/posts`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:POSTS', args);
return args;
});
},
editGroupPost(params) {
return window.API.call(
`groups/${params.groupId}/posts/${params.postId}`,
{
method: 'PUT',
params
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:POST', args);
return args;
});
},
createGroupPost(params) {
return window.API.call(`groups/${params.groupId}/posts`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:POST', args);
return args;
});
},
/**
* @param {{
* groupId: string,
* userId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
getGroupMember(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
params
};
// window.API.$emit('GROUP:MEMBER', args);
return args;
});
},
/**
* @param {{
* groupId: string,
* n: number,
* offset: number
* }} params
* @return { Promise<{json: any, params}> }
*/
getGroupMembers(params) {
return window.API.call(`groups/${params.groupId}/members`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:MEMBERS', args);
return args;
});
},
/**
* @param {{
* groupId: string,
* query: string,
* n: number,
* offset: number
* }} params
* @return { Promise<{json: any, params}> }
*/
getGroupMembersSearch(params) {
return window.API.call(`groups/${params.groupId}/members/search`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{
* groupId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
blockGroup(params) {
return window.API.call(`groups/${params.groupId}/block`, {
method: 'POST'
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{
* groupId: string,
* userId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
unblockGroup(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{
* groupId: string,
* userId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
sendGroupInvite(params) {
return window.API.call(`groups/${params.groupId}/invites`, {
method: 'POST',
params: {
userId: params.userId
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GROUP:INVITE', args);
return args;
});
},
/**
* @param {{
* groupId: string,
* userId: string
* }} params
* @return { Promise<{json: any, params}> }
*/
kickGroupMember(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:MEMBER:KICK', args);
return args;
});
},
/**
* @param {{ groupId: string, userId: string }} params
* @return { Promise<{json: any, params}> }
*/
banGroupMember(params) {
return window.API.call(`groups/${params.groupId}/bans`, {
method: 'POST',
params: {
userId: params.userId
}
}).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:MEMBER:BAN', args);
return args;
});
},
unbanGroupMember(params) {
return window.API.call(
`groups/${params.groupId}/bans/${params.userId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:MEMBER:UNBAN', args);
return args;
});
},
/**
* @param {{ groupId: string, userId: string }} params
* @return { Promise<{json: any, params}> }
*/
deleteSentGroupInvite(params) {
return window.API.call(
`groups/${params.groupId}/invites/${params.userId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:INVITE:DELETE', args);
return args;
});
},
deleteBlockedGroupRequest(params) {
return window.API.call(
`groups/${params.groupId}/members/${params.userId}`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:BLOCKED:DELETE', args);
return args;
});
},
acceptGroupInviteRequest(params) {
return window.API.call(
`groups/${params.groupId}/requests/${params.userId}`,
{
method: 'PUT',
params: {
action: 'accept'
}
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:INVITE:ACCEPT', args);
return args;
});
},
rejectGroupInviteRequest(params) {
return window.API.call(
`groups/${params.groupId}/requests/${params.userId}`,
{
method: 'PUT',
params: {
action: 'reject'
}
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:INVITE:REJECT', args);
return args;
});
},
blockGroupInviteRequest(params) {
return window.API.call(
`groups/${params.groupId}/requests/${params.userId}`,
{
method: 'PUT',
params: {
action: 'reject',
block: true
}
}
).then((json) => {
const args = {
json,
params
};
// useless code
// window.API.$emit('GROUP:INVITE:BLOCK', args);
return args;
});
},
getGroupBans(params) {
return window.API.call(`groups/${params.groupId}/bans`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroupAuditLogTypes(params) {
return window.API.call(`groups/${params.groupId}/auditLogTypes`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string, eventTypes: array }} params
* @return { Promise<{json: any, params}> }
*/
getGroupLogs(params) {
return window.API.call(`groups/${params.groupId}/auditLogs`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroupInvites(params) {
return window.API.call(`groups/${params.groupId}/invites`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroupJoinRequests(params) {
return window.API.call(`groups/${params.groupId}/requests`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
// window.API.$emit('GROUP:JOINREQUESTS', args);
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroupInstances(params) {
return window.API.call(
`users/${window.API.currentUser.id}/instances/groups/${params.groupId}`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
* @param {{ groupId: string }} params
* @return { Promise<{json: any, params}> }
*/
getGroupRoles(params) {
return window.API.call(`groups/${params.groupId}/roles`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
// useless code
// this.$emit('GROUP:ROLES', args);
return args;
});
},
getUsersGroupInstances() {
return window.API.call(
`users/${window.API.currentUser.id}/instances/groups`,
{
method: 'GET'
}
).then((json) => {
const args = {
json
};
window.API.$emit('GROUP:USER:INSTANCES', args);
return args;
});
},
/**
* @param {{
query: string,
n: number,
offset: number,
order: string,
sortBy: string
}} params
* @return { Promise<{json: any, params}> }
*/
groupSearch(params) {
return window.API.call(`groups`, {
method: 'GET',
params
}).then((json) => {
var args = {
json,
params
};
return args;
});
},
/**
* @param {{
groupId: string,
galleryId: string,
n: number,
offset: number
}} params
* @return { Promise<{json: any, params}> }
*/
getGroupGallery(params) {
return window.API.call(
`groups/${params.groupId}/galleries/${params.galleryId}`,
{
method: 'GET',
params: {
n: params.n,
offset: params.offset
}
}
).then((json) => {
const args = {
json,
params
};
return args;
});
}
// no place to use this
// getRequestedGroups() {
// return window.API.call(
// `users/${window.API.currentUser.id}/groups/requested`,
// {
// method: 'GET'
// }
// ).then((json) => {
// const args = {
// json
// };
// window.API.$emit('GROUP:REQUESTED', args);
// return args;
// });
// }
// ----------------- left over code -----------------
// /**
// * @param {{ groupId: string }} params
// * @return { Promise<{json: any, params}> }
// */
// API.getGroupAnnouncement = function (params) {
// return this.call(`groups/${params.groupId}/announcement`, {
// method: 'GET'
// }).then((json) => {
// var args = {
// json,
// params
// };
// this.$emit('GROUP:ANNOUNCEMENT', args);
// return args;
// });
// };
};
export default groupReq;

306
src/api/image.js Normal file
View File

@@ -0,0 +1,306 @@
const imageReq = {
// use in uploadAvatarImage
// need to test
async uploadAvatarFailCleanup(id) {
const json = await window.API.call(`file/${id}`, {
method: 'GET'
});
const fileId = json.id;
const fileVersion = json.versions[json.versions.length - 1].version;
window.API.call(`file/${fileId}/${fileVersion}/signature/finish`, {
method: 'PUT'
});
window.API.call(`file/${fileId}/${fileVersion}/file/finish`, {
method: 'PUT'
});
window.$app.avatarDialog.loading = false;
window.$app.changeAvatarImageDialogLoading = false;
},
async uploadAvatarImage(params, fileId) {
try {
return await window.API.call(`file/${fileId}`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params,
fileId
};
window.API.$emit('AVATARIMAGE:INIT', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadAvatarFailCleanup(fileId);
}
return void 0;
},
async uploadAvatarImageFileStart(params) {
try {
return await window.API.call(
`file/${params.fileId}/${params.fileVersion}/file/start`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:FILESTART', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadAvatarFailCleanup(params.fileId);
}
return void 0;
},
uploadAvatarImageFileFinish(params) {
return window.API.call(
`file/${params.fileId}/${params.fileVersion}/file/finish`,
{
method: 'PUT',
params: {
maxParts: 0,
nextPartNumber: 0
}
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:FILEFINISH', args);
return args;
});
},
async uploadAvatarImageSigStart(params) {
try {
return await window.API.call(
`file/${params.fileId}/${params.fileVersion}/signature/start`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:SIGSTART', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadAvatarFailCleanup(params.fileId);
}
return void 0;
},
uploadAvatarImageSigFinish(params) {
return window.API.call(
`file/${params.fileId}/${params.fileVersion}/signature/finish`,
{
method: 'PUT',
params: {
maxParts: 0,
nextPartNumber: 0
}
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:SIGFINISH', args);
return args;
});
},
setAvatarImage(params) {
return window.API.call(`avatars/${params.id}`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:SET', args);
window.API.$emit('AVATAR', args);
return args;
});
},
// use in uploadWorldImage
// need to test
async uploadWorldFailCleanup(id) {
const json = await window.API.call(`file/${id}`, {
method: 'GET'
});
const fileId = json.id;
const fileVersion = json.versions[json.versions.length - 1].version;
window.API.call(`file/${fileId}/${fileVersion}/signature/finish`, {
method: 'PUT'
});
window.API.call(`file/${fileId}/${fileVersion}/file/finish`, {
method: 'PUT'
});
window.$app.worldDialog.loading = false;
window.$app.changeWorldImageDialogLoading = false;
},
async uploadWorldImage(params, fileId) {
try {
return await window.API.call(`file/${fileId}`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params,
fileId
};
window.API.$emit('WORLDIMAGE:INIT', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadWorldFailCleanup(fileId);
}
return void 0;
},
async uploadWorldImageFileStart(params) {
try {
return await window.API.call(
`file/${params.fileId}/${params.fileVersion}/file/start`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:FILESTART', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadWorldFailCleanup(params.fileId);
}
return void 0;
},
uploadWorldImageFileFinish(params) {
return window.API.call(
`file/${params.fileId}/${params.fileVersion}/file/finish`,
{
method: 'PUT',
params: {
maxParts: 0,
nextPartNumber: 0
}
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:FILEFINISH', args);
return args;
});
},
async uploadWorldImageSigStart(params) {
try {
return await window.API.call(
`file/${params.fileId}/${params.fileVersion}/signature/start`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:SIGSTART', args);
return args;
});
} catch (err) {
console.error(err);
window.API.uploadWorldFailCleanup(params.fileId);
}
return void 0;
},
uploadWorldImageSigFinish(params) {
return window.API.call(
`file/${params.fileId}/${params.fileVersion}/signature/finish`,
{
method: 'PUT',
params: {
maxParts: 0,
nextPartNumber: 0
}
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:SIGFINISH', args);
return args;
});
},
setWorldImage(params) {
return window.API.call(`worlds/${params.id}`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:SET', args);
window.API.$emit('WORLD', args);
return args;
});
},
getAvatarImages(params) {
return window.API.call(`file/${params.fileId}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('AVATARIMAGE:GET', args);
return args;
});
},
getWorldImages(params) {
return window.API.call(`file/${params.fileId}`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLDIMAGE:GET', args);
return args;
});
}
};
export default imageReq;

59
src/api/index.js Normal file
View File

@@ -0,0 +1,59 @@
/**
* API requests
* Export all API requests from here
*
* "window.API" is used as app.js is a large IIFE, preventing direct API export. No current issues
* Refactoring may be required
*/
import userRequest from './user';
import worldRequest from './world';
import instanceRequest from './instance';
import friendRequest from './friend';
import avatarRequest from './avatar';
import notificationRequest from './notification';
import playerModerationRequest from './playerModeration';
import avatarModerationRequest from './avatarModeration';
import favoriteRequest from './favorite';
import vrcPlusIconRequest from './vrcPlusIcon';
import vrcPlusImageRequest from './vrcPlusImage';
import inviteMessagesRequest from './inviteMessages';
import imageRequest from './image';
import miscRequest from './misc';
import groupRequest from './group';
window.request = {
userRequest,
worldRequest,
instanceRequest,
friendRequest,
avatarRequest,
notificationRequest,
playerModerationRequest,
avatarModerationRequest,
favoriteRequest,
vrcPlusIconRequest,
vrcPlusImageRequest,
inviteMessagesRequest,
imageRequest,
miscRequest,
groupRequest
};
export {
userRequest,
worldRequest,
instanceRequest,
friendRequest,
avatarRequest,
notificationRequest,
playerModerationRequest,
avatarModerationRequest,
favoriteRequest,
vrcPlusIconRequest,
vrcPlusImageRequest,
inviteMessagesRequest,
imageRequest,
miscRequest,
groupRequest
};

140
src/api/instance.js Normal file
View File

@@ -0,0 +1,140 @@
// #region | API: Instance
const instanceReq = {
/**
* @param {{worldId: string, instanceId: string}} params
* @returns {Promise<{json: any, params}>}
*/
getInstance(params) {
return window.API.call(
`instances/${params.worldId}:${params.instanceId}`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('INSTANCE', args);
return args;
});
},
/**
* CreateInstanceParameter
* @typedef {Object} CreateInstanceParameter
* @property {string} worldId
* @property {string} type
* @property {string} region
* @property {string} ownerId
* @property {string[]} roleIds
* @property {string} groupAccessType
* @property {boolean} queueEnabled
*/
/**
* @param {CreateInstanceParameter} params
* @returns {Promise<{json: any, params}>}
*/
createInstance(params) {
return window.API.call('instances', {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('INSTANCE', args);
return args;
});
},
/**
* @param {{ worldId: string, instanceId: string, shortName: string }} instance
* @returns {Promise<{instance, json: T, params: {}}>}
*/
getInstanceShortName(instance) {
const params = {};
if (instance.shortName) {
params.shortName = instance.shortName;
}
return window.API.call(
`instances/${instance.worldId}:${instance.instanceId}/shortName`,
{
method: 'GET',
params
}
).then((json) => {
const args = {
json,
instance,
params
};
return args;
});
},
/**
* @param {{ shortName: string }} params
* @returns {Promise<{json: any, params}>}
*/
getInstanceFromShortName(params) {
return window.API.call(`instances/s/${params.shortName}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('INSTANCE', args);
return args;
});
},
/**
* Send invite to current user.
* @param {{ worldId: string, instanceId: string, shortName?: string }} instance
* @returns {Promise<{instance, json: any, params}>}
*/
selfInvite(instance) {
/**
* @type {{ shortName?: string }}
*/
const params = {};
if (instance.shortName) {
params.shortName = instance.shortName;
}
return window.API.call(
`invite/myself/to/${instance.worldId}:${instance.instanceId}`,
{
method: 'POST',
params
}
)
.then((json) => {
return {
json,
instance,
params
};
})
.catch((err) => {
if (err?.error?.message) {
window.$app.$message({
message: err.error.message,
type: 'error'
});
throw err;
}
window.$app.$message({
message: window.$t('message.instance.not_allowed'),
type: 'error'
});
throw err;
});
}
};
// #endregion
export default instanceReq;

41
src/api/inviteMessages.js Normal file
View File

@@ -0,0 +1,41 @@
// #region | App: Invite Messages
const inviteMessagesReq = {
refreshInviteMessageTableData(messageType) {
return window.API.call(
`message/${window.API.currentUser.id}/${messageType}`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
messageType
};
window.API.$emit(`INVITE:${messageType.toUpperCase()}`, args);
return args;
});
},
editInviteMessage(params, messageType, slot) {
return window.API.call(
`message/${window.API.currentUser.id}/${messageType}/${slot}`,
{
method: 'PUT',
params
}
).then((json) => {
const args = {
json,
params,
messageType,
slot
};
return args;
});
}
};
// #endregion
export default inviteMessagesReq;

179
src/api/misc.js Normal file
View File

@@ -0,0 +1,179 @@
const miscReq = {
getBundles(fileId) {
return window.API.call(`file/${fileId}`, {
method: 'GET'
}).then((json) => {
const args = {
json
};
return args;
});
},
saveNote(params) {
return window.API.call('userNotes', {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTE', args);
return args;
});
},
/**
* @param {{
* userId: string,
* contentType: string,
* reason: string,
* type: string
* }} params
* @return { Promise<{json: any, params}> }
*/
reportUser(params) {
return window.API.call(`feedback/${params.userId}/user`, {
method: 'POST',
params: {
contentType: params.contentType,
reason: params.reason,
type: params.type
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FEEDBACK:REPORT:USER', args);
return args;
});
},
/**
* @param {{
* fileId: string,
* version: number
* }} params
* @return { Promise<{json: any, params}> }
*/
getFileAnalysis(params) {
return window.API.call(
`analysis/${params.fileId}/${params.version}/${params.variant}`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
params
};
// window.API.$emit('FILE:ANALYSIS', args);
return args;
});
},
getVRChatCredits() {
return window.API.call(`user/${window.API.currentUser.id}/balance`, {
method: 'GET'
}).then((json) => {
const args = {
json
};
window.API.$emit('VRCCREDITS', args);
return args;
});
},
/**
* @param {{
* location: string,
* hardClose: boolean
* }} params
* @returns {Promise<{json: any, params}>}
*/
closeInstance(params) {
return window.API.call(`instances/${params.location}`, {
method: 'DELETE',
params: {
hardClose: params.hardClose ?? false
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('INSTANCE:CLOSE', args);
return args;
});
},
/**
* @param {{
* worldId: string
* }} params
* @returns {Promise<{json: any, params}>}
*/
deleteWorldPersistData(params) {
return window.API.call(
`users/${window.API.currentUser.id}/${params.worldId}/persist`,
{
method: 'DELETE'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:PERSIST:DELETE', args);
return args;
});
},
/**
* @param {{
* worldId: string
* }} params
* @returns {Promise<{json: any, params}>}
*/
hasWorldPersistData(params) {
return window.API.call(
`users/${window.API.currentUser.id}/${params.worldId}/persist/exists`,
{
method: 'GET'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:PERSIST:HAS', args);
return args;
});
},
updateBadge(params) {
return window.API.call(
`users/${window.API.currentUser.id}/badges/${params.badgeId}`,
{
method: 'PUT',
params: {
userId: window.API.currentUser.id,
badgeId: params.badgeId,
hidden: params.hidden,
showcased: params.showcased
}
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('BADGE:UPDATE', args);
return args;
});
}
};
export default miscReq;

305
src/api/notification.js Normal file
View File

@@ -0,0 +1,305 @@
// #region | API: Notification
const notificationReq = {
/** @typedef {{
* n: number,
* offset: number,
* sent: boolean,
* type: string,
* // (ISO8601 or 'five_minutes_ago')
* after: 'five_minutes_ago' | (string & {})
* }} NotificationFetchParameter
*/
/**
*
* @param {NotificationFetchParameter} params
* @returns {Promise<{json: any, params}>}
*/
getNotifications(params) {
return window.API.call('auth/user/notifications', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:LIST', args);
return args;
});
},
getHiddenFriendRequests(params) {
return window.API.call('auth/user/notifications', {
method: 'GET',
params: {
type: 'friendRequest',
hidden: true,
...params
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:LIST:HIDDEN', args);
return args;
});
},
getNotificationsV2(params) {
return window.API.call('notifications', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:V2:LIST', args);
return args;
});
},
/**
* string that represents valid serialized JSON of T's value
* @template T=any
* @typedef {string} JsonString
*/
/**
* @param {{
* receiverUserId: string,
* type: string,
* message: string,
* seen: boolean,
* details: JsonString<any>
* }} params
* @param receiverUserId
* @return { Promise<{json: any, params}> }
*/
sendInvite(params, receiverUserId) {
return window.API.call(`invite/${receiverUserId}`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params,
receiverUserId
};
window.API.$emit('NOTIFICATION:INVITE:SEND', args);
return args;
});
},
sendInvitePhoto(params, receiverUserId) {
return window.API.call(`invite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: window.$app.uploadImage
}).then((json) => {
const args = {
json,
params,
receiverUserId
};
window.API.$emit('NOTIFICATION:INVITE:PHOTO:SEND', args);
return args;
});
},
sendRequestInvite(params, receiverUserId) {
return window.API.call(`requestInvite/${receiverUserId}`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params,
receiverUserId
};
window.API.$emit('NOTIFICATION:REQUESTINVITE:SEND', args);
return args;
});
},
sendRequestInvitePhoto(params, receiverUserId) {
return window.API.call(`requestInvite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: window.$app.uploadImage
}).then((json) => {
const args = {
json,
params,
receiverUserId
};
window.API.$emit('NOTIFICATION:REQUESTINVITE:PHOTO:SEND', args);
return args;
});
},
sendInviteResponse(params, inviteId) {
return window.API.call(`invite/${inviteId}/response`, {
method: 'POST',
params,
inviteId
}).then((json) => {
const args = {
json,
params,
inviteId
};
window.API.$emit('INVITE:RESPONSE:SEND', args);
return args;
});
},
sendInviteResponsePhoto(params, inviteId) {
return window.API.call(`invite/${inviteId}/response/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: window.$app.uploadImage,
inviteId
}).then((json) => {
const args = {
json,
params,
inviteId
};
window.API.$emit('INVITE:RESPONSE:PHOTO:SEND', args);
return args;
});
},
/**
* @param {{ notificationId: string }} params
* @return { Promise<{json: any, params}> }
*/
acceptFriendRequestNotification(params) {
return window.API.call(
`auth/user/notifications/${params.notificationId}/accept`,
{
method: 'PUT'
}
)
.then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:ACCEPT', args);
return args;
})
.catch((err) => {
// if friend request could not be found, delete it
if (err && err.message && err.message.includes('404')) {
window.API.$emit('NOTIFICATION:HIDE', { params });
}
});
},
/**
* @param {{ notificationId: string }} params
* @return { Promise<{json: any, params}> }
*/
hideNotification(params) {
return window.API.call(
`auth/user/notifications/${params.notificationId}/hide`,
{
method: 'PUT'
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:HIDE', args);
return args;
});
},
// ------------------- need to test -------------------
/**
* @param {{
* notificationId: string,
* responseType: string,
* responseData: string
* }} params
* @return { Promise<{json: any, params}> }
*/
sendNotificationResponse(params) {
return window.API.call(
`notifications/${params.notificationId}/respond`,
{
method: 'POST',
params
}
)
.then((json) => {
const args = {
json,
params
};
window.API.$emit('NOTIFICATION:RESPONSE', args);
return args;
})
.catch((err) => {
// TODO: need to test
// something went wrong, lets assume it's already expired
window.API.$emit('NOTIFICATION:HIDE', { params });
notificationReq.hideNotificationV2(params.notificationId);
throw err;
});
},
// use in sendNotificationResponse
hideNotificationV2(notificationId) {
return window.API.call(`notifications/${notificationId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params: {
notificationId
}
};
window.API.$emit('NOTIFICATION:V2:HIDE', args);
return args;
});
}
// ------------------ look like no place use these requests ------------------
// sendInviteGalleryPhoto(params, receiverUserId) {
// return window.API.call(`invite/${receiverUserId}/photo`, {
// method: 'POST',
// params
// }).then((json) => {
// const args = {
// json,
// params,
// receiverUserId
// };
// window.API.$emit('NOTIFICATION:INVITE:GALLERYPHOTO:SEND', args);
// return args;
// });
// },
// API.clearNotifications = function () {
// return this.call('auth/user/notifications/clear', {
// method: 'PUT'
// }).then((json) => {
// var args = {
// json
// };
// // FIXME: NOTIFICATION:CLEAR 핸들링
// this.$emit('NOTIFICATION:CLEAR', args);
// return args;
// });
// };
};
// #endregion
export default notificationReq;

View File

@@ -0,0 +1,56 @@
// #region | API: PlayerModeration
const playerModerationReq = {
getPlayerModerations() {
return window.API.call('auth/user/playermoderations', {
method: 'GET'
}).then((json) => {
const args = {
json
};
window.API.$emit('PLAYER-MODERATION:LIST', args);
return args;
});
},
/**
* @param {{ moderated: string, type: string }} params
* @return { Promise<{json: any, params}> }
*/
// old-way: POST auth/user/blocks {blocked:userId}
sendPlayerModeration(params) {
return window.API.call('auth/user/playermoderations', {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('PLAYER-MODERATION:SEND', args);
return args;
});
},
/**
* @param {{ moderated: string, type: string }} params
* @return { Promise<{json: any, params}> }
*/
// old-way: PUT auth/user/unblocks {blocked:userId}
deletePlayerModeration(params) {
return window.API.call('auth/user/unplayermoderate', {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('PLAYER-MODERATION:DELETE', args);
return args;
});
}
};
// #endregion
export default playerModerationReq;

131
src/api/user.js Normal file
View File

@@ -0,0 +1,131 @@
// #region | API: User
const userReq = {
/**
* Fetch user from API.
* @param {{ userId: string }} params identifier of registered user
* @returns {Promise<{json: any, params}>}
*/
getUser(params) {
return window.API.call(`users/${params.userId}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('USER', args);
return args;
});
},
/**
* Fetch user from cache if they're in it. Otherwise, calls API.
* @param {{ userId: string }} params identifier of registered user
* @returns {Promise<{json: any, params}>}
*/
getCachedUser(params) {
return new Promise((resolve, reject) => {
const ref = window.API.cachedUsers.get(params.userId);
if (typeof ref === 'undefined') {
userReq.getUser(params).catch(reject).then(resolve);
} else {
resolve({
cache: true,
json: ref,
params,
ref
});
}
});
},
/**
* @typedef {object} GetUsersParameters
* @property {number} n
* @property {number} offset
* @property {string} search
* @property {'nuisanceFactor' | 'created' | '_created_at' | 'last_login'} sort
* @property {'ascending' | 'descending'} order
*/
/**
* Fetch multiple users from API.
* @param params {GetUsersParameters} filtering and sorting parameters
* @returns {Promise<{json: any, params}>}
*/
getUsers(params) {
return window.API.call('users', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('USER:LIST', args);
return args;
});
},
/**
* @param params {string[]}
* @returns {Promise<{json: any, params}>}
*/
addUserTags(params) {
return window.API.call(`users/${window.API.currentUser.id}/addTags`, {
method: 'POST',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('USER:CURRENT:SAVE', args);
return args;
});
},
/**
* @param params {string[]}
* @returns {Promise<{json: any, params}>}
*/
removeUserTags(params) {
return window.API.call(
`users/${window.API.currentUser.id}/removeTags`,
{
method: 'POST',
params
}
).then((json) => {
const args = {
json,
params
};
window.API.$emit('USER:CURRENT:SAVE', args);
return args;
});
},
/**
* @param params {{ userId: string }}
* @returns {Promise<{json: any, params}>}
*/
getUserFeedback(params) {
return window.API.call(`users/${params.userId}/feedback`, {
method: 'GET',
params: {
n: 100
}
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('USER:FEEDBACK', args);
return args;
});
}
};
// #endregion
export default userReq;

66
src/api/vrcPlusIcon.js Normal file
View File

@@ -0,0 +1,66 @@
// #region | App: VRCPlus Icons
const VRCPlusIconsReq = {
getFileList(params) {
return window.API.call('files', {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('FILES:LIST', args);
return args;
});
},
deleteFile(fileId) {
return window.API.call(`file/${fileId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
fileId
};
return args;
});
},
uploadVRCPlusIcon(imageData) {
const params = {
tag: 'icon'
};
return window.API.call('file/image', {
uploadImage: true,
matchingDimensions: true,
postData: JSON.stringify(params),
imageData
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('VRCPLUSICON:ADD', args);
return args;
});
}
// unused
// images.pug line 63
// deleteFileVersion(params) {
// return window.API.call(`file/${params.fileId}/${params.version}`, {
// method: 'DELETE'
// }).then((json) => {
// const args = {
// json,
// params
// };
// return args;
// });
// }
};
// #endregion
export default VRCPlusIconsReq;

126
src/api/vrcPlusImage.js Normal file
View File

@@ -0,0 +1,126 @@
const vrcPlusImageReq = {
uploadGalleryImage(imageData) {
const params = {
tag: 'gallery'
};
return window.API.call('file/image', {
uploadImage: true,
matchingDimensions: false,
postData: JSON.stringify(params),
imageData
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('GALLERYIMAGE:ADD', args);
return args;
});
},
uploadSticker(imageData, params) {
return window.API.call('file/image', {
uploadImage: true,
matchingDimensions: true,
postData: JSON.stringify(params),
imageData
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('STICKER:ADD', args);
return args;
});
},
getPrints(params) {
return window.API.call(`prints/user/${window.API.currentUser.id}`, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('PRINT:LIST', args);
return args;
});
},
deletePrint(printId) {
return window.API.call(`prints/${printId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
printId
};
window.API.$emit('PRINT:DELETE', args);
return args;
});
},
uploadPrint(imageData, cropWhiteBorder, params) {
return window.API.call('prints', {
uploadImagePrint: true,
cropWhiteBorder,
postData: JSON.stringify(params),
imageData
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('PRINT:ADD', args);
return args;
});
},
getPrint(params) {
return window.API.call(`prints/${params.printId}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('PRINT', args);
return args;
});
},
uploadEmoji(imageData, params) {
return window.API.call('file/image', {
uploadImage: true,
matchingDimensions: true,
postData: JSON.stringify(params),
imageData
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('EMOJI:ADD', args);
return args;
});
}
// ----------- no place uses this function ------------
// editPrint(params) {
// return window.API.call(`prints/${params.printId}`, {
// method: 'POST',
// params
// }).then((json) => {
// const args = {
// json,
// params
// };
// window.API.$emit('PRINT:EDIT', args);
// return args;
// });
// },
};
export default vrcPlusImageReq;

151
src/api/world.js Normal file
View File

@@ -0,0 +1,151 @@
// #region | API: World
const worldReq = {
/**
* @param {{worldId: string}} params
* @returns {Promise<{json: any, params}>}
*/
getWorld(params) {
return window.API.call(`worlds/${params.worldId}`, {
method: 'GET'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD', args);
return args;
});
},
/**
* @param {{worldId: string}} params
* @returns {Promise<{json: any, params}>}
*/
getCachedWorld(params) {
return new Promise((resolve, reject) => {
const ref = window.API.cachedWorlds.get(params.worldId);
if (typeof ref === 'undefined') {
worldReq.getWorld(params).catch(reject).then(resolve);
} else {
resolve({
cache: true,
json: ref,
params,
ref
});
}
});
},
/**
* @typedef {object} WorldSearchParameter
* @property {number} n
* @property {number} offset
* @property {string} search
* @property {string} userId
* @property {'me' | 'friend'} user
* @property {'popularity' | 'heat' | 'trust' | 'shuffle' | 'favorites' | 'reportScore' | 'reportCount' | 'publicationDate' | 'labsPublicationDate' | 'created' | '_created_at' | 'updated' | '_updated_at' | 'order'} sort
* @property {'ascending' | 'descending'} order
* @property {'public' | 'private' | 'hidden' | 'all'} releaseStatus
* @property {boolean} featured
*/
/**
*
* @param {WorldSearchParameter} params
* @param {string?} option sub-path of calling endpoint
* @returns {Promise<{json: any, params, option}>}
*/
getWorlds(params, option) {
let endpoint = 'worlds';
if (typeof option !== 'undefined') {
endpoint = `worlds/${option}`;
}
return window.API.call(endpoint, {
method: 'GET',
params
}).then((json) => {
const args = {
json,
params,
option
};
window.API.$emit('WORLD:LIST', args);
return args;
});
},
/**
* @param {{worldId: string}} params
* @returns {Promise<{json: any, params}>}
*/
deleteWorld(params) {
return window.API.call(`worlds/${params.worldId}`, {
method: 'DELETE'
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:DELETE', args);
return args;
});
},
/**
* @param {{id: string}} params
* @returns {Promise<{json: any, params}>}
*/
saveWorld(params) {
return window.API.call(`worlds/${params.id}`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:SAVE', args);
return args;
});
},
/**
* @param {{worldId: string}} params
* @returns {Promise<{json: any, params}>}
*/
publishWorld(params) {
return window.API.call(`worlds/${params.worldId}/publish`, {
method: 'PUT',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:SAVE', args);
return args;
});
},
/**
* @param {{worldId: string}} params
* @returns {Promise<{json: any, params}>}
*/
unpublishWorld(params) {
return window.API.call(`worlds/${params.worldId}/publish`, {
method: 'DELETE',
params
}).then((json) => {
const args = {
json,
params
};
window.API.$emit('WORLD:SAVE', args);
return args;
});
}
};
// #endregion
export default worldReq;