Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
7be88b7816 | |||
faabb039a5 | |||
15e4cf1243 | |||
75764e59e1 | |||
f664cf09c0 | |||
0c3e9dd5e0 | |||
0bc7d28f58 | |||
17bb34941b | |||
04cd3377ee | |||
326bd5e094 | |||
987799e9db | |||
19c846afaf | |||
ea9265b30b | |||
0516353afd |
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "1.4.0",
|
||||
"clientVersion": "1.0.5158",
|
||||
"version": "1.6.0",
|
||||
"clientVersion": "1.0.5172",
|
||||
"codename": "nighthike",
|
||||
"main": "./built/index.js",
|
||||
"private": true,
|
||||
@ -88,7 +88,7 @@
|
||||
"autwh": "0.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bootstrap-vue": "2.0.0-rc.6",
|
||||
"cafy": "7.0.1",
|
||||
"cafy": "8.0.0",
|
||||
"chai": "4.1.2",
|
||||
"chai-http": "4.0.0",
|
||||
"chalk": "2.4.1",
|
||||
|
@ -8,8 +8,8 @@ export const isNotAnId = x => !isAnId(x);
|
||||
* ID
|
||||
*/
|
||||
export default class ID extends Query<mongo.ObjectID> {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.transform = v => {
|
||||
if (isAnId(v) && !mongo.ObjectID.prototype.isPrototypeOf(v)) {
|
||||
@ -19,7 +19,7 @@ export default class ID extends Query<mongo.ObjectID> {
|
||||
}
|
||||
};
|
||||
|
||||
this.pushValidator(v => {
|
||||
this.push(v => {
|
||||
if (!mongo.ObjectID.prototype.isPrototypeOf(v) && isNotAnId(v)) {
|
||||
return new Error('must-be-an-id');
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import MiOS from '../mios';
|
||||
import MiOS from '../../mios';
|
||||
import { version as current } from '../../config';
|
||||
|
||||
export default async function(mios: MiOS, force = false, silent = false) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Stream from './stream';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Channel stream connection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Drive stream connection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Global timeline stream connection
|
||||
|
@ -2,7 +2,7 @@ import * as merge from 'object-assign-deep';
|
||||
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Home stream connection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Local timeline stream connection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Messaging index stream connection
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Stream from './stream';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Messaging stream connection
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Stream from './stream';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
export class OthelloGameStream extends Stream {
|
||||
constructor(os: MiOS, me, game) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import StreamManager from './stream-manager';
|
||||
import Stream from './stream';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
export class OthelloStream extends Stream {
|
||||
constructor(os: MiOS, me) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Stream from './stream';
|
||||
import StreamManager from './stream-manager';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Server stream connection
|
||||
|
@ -2,7 +2,7 @@ import { EventEmitter } from 'eventemitter3';
|
||||
import * as uuid from 'uuid';
|
||||
import * as ReconnectingWebsocket from 'reconnecting-websocket';
|
||||
import { wsUrl } from '../../../config';
|
||||
import MiOS from '../../mios';
|
||||
import MiOS from '../../../mios';
|
||||
|
||||
/**
|
||||
* Misskey stream connection
|
||||
|
@ -35,4 +35,5 @@ export default Vue.extend({
|
||||
margin 0
|
||||
border-radius inherit
|
||||
vertical-align bottom
|
||||
transition border-radius 1s ease
|
||||
</style>
|
||||
|
@ -5,7 +5,7 @@
|
||||
cx="50%" cy="50%"
|
||||
fill="none"
|
||||
stroke-width="0.1"
|
||||
stroke="rgba(#000, 0.05)"/>
|
||||
stroke="rgba(0, 0, 0, 0.05)"/>
|
||||
<circle
|
||||
:r="r"
|
||||
cx="50%" cy="50%"
|
||||
|
@ -1,4 +1,4 @@
|
||||
import OS from '../../common/mios';
|
||||
import OS from '../../mios';
|
||||
import { apiUrl } from '../../config';
|
||||
import CropWindow from '../views/components/crop-window.vue';
|
||||
import ProgressDialog from '../views/components/progress-dialog.vue';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import OS from '../../common/mios';
|
||||
import OS from '../../mios';
|
||||
import { apiUrl } from '../../config';
|
||||
import CropWindow from '../views/components/crop-window.vue';
|
||||
import ProgressDialog from '../views/components/progress-dialog.vue';
|
||||
|
@ -250,7 +250,7 @@ root(isDark)
|
||||
> div
|
||||
display flex
|
||||
margin 0 auto
|
||||
max-width 1200px - 32px
|
||||
max-width 1220px - 32px
|
||||
|
||||
> div
|
||||
width 50%
|
||||
@ -281,7 +281,7 @@ root(isDark)
|
||||
display flex
|
||||
justify-content center
|
||||
margin 0 auto
|
||||
max-width 1200px
|
||||
max-width 1220px
|
||||
|
||||
> *
|
||||
.customize-container
|
||||
|
@ -46,9 +46,10 @@ export default Vue.extend({
|
||||
this.$store.commit('setUiHeaderHeight', 48);
|
||||
|
||||
if ((this as any).os.isSignedIn) {
|
||||
const ago = (new Date().getTime() - new Date((this as any).os.i.lastUsedAt).getTime()) / 1000
|
||||
const ago = (new Date().getTime() - new Date((this as any).os.i.lastUsedAt).getTime()) / 1000;
|
||||
const isHisasiburi = ago >= 3600;
|
||||
(this as any).os.i.lastUsedAt = new Date();
|
||||
(this as any).os.bakeMe();
|
||||
if (isHisasiburi) {
|
||||
(this.$refs.welcomeback as any).style.display = 'block';
|
||||
(this.$refs.main as any).style.overflow = 'hidden';
|
||||
@ -132,7 +133,7 @@ root(isDark)
|
||||
line-height 48px
|
||||
margin 0
|
||||
text-align center
|
||||
color #888
|
||||
color isDark ? #fff : #888
|
||||
opacity 0
|
||||
|
||||
> .container
|
||||
|
@ -2,8 +2,8 @@
|
||||
<div class="header" :data-is-dark-background="user.bannerUrl != null">
|
||||
<div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div>
|
||||
<div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div>
|
||||
<div class="banner-container" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl}?thumbnail&size=2048)` : ''">
|
||||
<div class="banner" ref="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl}?thumbnail&size=2048)` : ''" @click="onBannerClick"></div>
|
||||
<div class="banner-container" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''">
|
||||
<div class="banner" ref="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''" @click="onBannerClick"></div>
|
||||
<div class="fade"></div>
|
||||
</div>
|
||||
<div class="container">
|
||||
|
@ -14,7 +14,7 @@ import ElementLocaleJa from 'element-ui/lib/locale/lang/ja';
|
||||
|
||||
import App from './app.vue';
|
||||
import checkForUpdate from './common/scripts/check-for-update';
|
||||
import MiOS, { API } from './common/mios';
|
||||
import MiOS, { API } from './mios';
|
||||
import { version, codename, lang } from './config';
|
||||
|
||||
let elementLocale;
|
||||
|
@ -3,19 +3,19 @@ import { EventEmitter } from 'eventemitter3';
|
||||
import * as merge from 'object-assign-deep';
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
import initStore from '../store';
|
||||
import { hostname, apiUrl, swPublickey, version, lang, googleMapsApiKey } from '../config';
|
||||
import Progress from './scripts/loading';
|
||||
import Connection from './scripts/streaming/stream';
|
||||
import { HomeStreamManager } from './scripts/streaming/home';
|
||||
import { DriveStreamManager } from './scripts/streaming/drive';
|
||||
import { ServerStreamManager } from './scripts/streaming/server';
|
||||
import { MessagingIndexStreamManager } from './scripts/streaming/messaging-index';
|
||||
import { OthelloStreamManager } from './scripts/streaming/othello';
|
||||
import initStore from './store';
|
||||
import { hostname, apiUrl, swPublickey, version, lang, googleMapsApiKey } from './config';
|
||||
import Progress from './common/scripts/loading';
|
||||
import Connection from './common/scripts/streaming/stream';
|
||||
import { HomeStreamManager } from './common/scripts/streaming/home';
|
||||
import { DriveStreamManager } from './common/scripts/streaming/drive';
|
||||
import { ServerStreamManager } from './common/scripts/streaming/server';
|
||||
import { MessagingIndexStreamManager } from './common/scripts/streaming/messaging-index';
|
||||
import { OthelloStreamManager } from './common/scripts/streaming/othello';
|
||||
|
||||
import Err from '../common/views/components/connect-failed.vue';
|
||||
import { LocalTimelineStreamManager } from './scripts/streaming/local-timeline';
|
||||
import { GlobalTimelineStreamManager } from './scripts/streaming/global-timeline';
|
||||
import Err from './common/views/components/connect-failed.vue';
|
||||
import { LocalTimelineStreamManager } from './common/scripts/streaming/local-timeline';
|
||||
import { GlobalTimelineStreamManager } from './common/scripts/streaming/global-timeline';
|
||||
|
||||
//#region api requests
|
||||
let spinner = null;
|
@ -59,9 +59,10 @@ export default Vue.extend({
|
||||
}
|
||||
});
|
||||
|
||||
const ago = (new Date().getTime() - new Date((this as any).os.i.lastUsedAt).getTime()) / 1000
|
||||
const ago = (new Date().getTime() - new Date((this as any).os.i.lastUsedAt).getTime()) / 1000;
|
||||
const isHisasiburi = ago >= 3600;
|
||||
(this as any).os.i.lastUsedAt = new Date();
|
||||
(this as any).os.bakeMe();
|
||||
if (isHisasiburi) {
|
||||
(this.$refs.welcomeback as any).style.display = 'block';
|
||||
(this.$refs.main as any).style.overflow = 'hidden';
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div class="is-suspended" v-if="user.isSuspended"><p>%fa:exclamation-triangle% %i18n:@is-suspended%</p></div>
|
||||
<div class="is-remote" v-if="user.host != null"><p>%fa:exclamation-triangle% %i18n:@is-remote%<a :href="user.url || user.uri" target="_blank">%i18n:@view-remote%</a></p></div>
|
||||
<header>
|
||||
<div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl}?thumbnail&size=1024)` : ''"></div>
|
||||
<div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''"></div>
|
||||
<div class="body">
|
||||
<div class="top">
|
||||
<a class="avatar">
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Vuex from 'vuex';
|
||||
import MiOS from './common/mios';
|
||||
import MiOS from './mios';
|
||||
|
||||
const defaultSettings = {
|
||||
home: [],
|
||||
|
25
src/drive/gen-thumbnail.ts
Normal file
25
src/drive/gen-thumbnail.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import * as stream from 'stream';
|
||||
import * as Gm from 'gm';
|
||||
import { IDriveFile, getDriveFileBucket } from '../models/drive-file';
|
||||
|
||||
const gm = Gm.subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
|
||||
export default async function(file: IDriveFile): Promise<stream.Readable> {
|
||||
if (!/^image\/.*$/.test(file.contentType)) return null;
|
||||
|
||||
const bucket = await getDriveFileBucket();
|
||||
const readable = bucket.openDownloadStream(file._id);
|
||||
|
||||
const g = gm(readable);
|
||||
|
||||
const stream = g
|
||||
.resize(256, 256)
|
||||
.compress('jpeg')
|
||||
.quality(70)
|
||||
.interlace('line')
|
||||
.stream();
|
||||
|
||||
return stream;
|
||||
}
|
61
src/models/drive-file-thumbnail.ts
Normal file
61
src/models/drive-file-thumbnail.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import monkDb, { nativeDbConn } from '../db/mongodb';
|
||||
|
||||
const DriveFileThumbnail = monkDb.get<IDriveFileThumbnail>('driveFileThumbnails.files');
|
||||
DriveFileThumbnail.createIndex('metadata.originalId', { sparse: true, unique: true });
|
||||
export default DriveFileThumbnail;
|
||||
|
||||
export const DriveFileThumbnailChunk = monkDb.get('driveFileThumbnails.chunks');
|
||||
|
||||
export const getDriveFileThumbnailBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||
const db = await nativeDbConn();
|
||||
const bucket = new mongo.GridFSBucket(db, {
|
||||
bucketName: 'driveFileThumbnails'
|
||||
});
|
||||
return bucket;
|
||||
};
|
||||
|
||||
export type IMetadata = {
|
||||
originalId: mongo.ObjectID;
|
||||
};
|
||||
|
||||
export type IDriveFileThumbnail = {
|
||||
_id: mongo.ObjectID;
|
||||
uploadDate: Date;
|
||||
md5: string;
|
||||
filename: string;
|
||||
contentType: string;
|
||||
metadata: IMetadata;
|
||||
};
|
||||
|
||||
/**
|
||||
* DriveFileThumbnailを物理削除します
|
||||
*/
|
||||
export async function deleteDriveFileThumbnail(driveFile: string | mongo.ObjectID | IDriveFileThumbnail) {
|
||||
let d: IDriveFileThumbnail;
|
||||
|
||||
// Populate
|
||||
if (mongo.ObjectID.prototype.isPrototypeOf(driveFile)) {
|
||||
d = await DriveFileThumbnail.findOne({
|
||||
_id: driveFile
|
||||
});
|
||||
} else if (typeof driveFile === 'string') {
|
||||
d = await DriveFileThumbnail.findOne({
|
||||
_id: new mongo.ObjectID(driveFile)
|
||||
});
|
||||
} else {
|
||||
d = driveFile as IDriveFileThumbnail;
|
||||
}
|
||||
|
||||
if (d == null) return;
|
||||
|
||||
// このDriveFileThumbnailのチャンクをすべて削除
|
||||
await DriveFileThumbnailChunk.remove({
|
||||
files_id: d._id
|
||||
});
|
||||
|
||||
// このDriveFileThumbnailを削除
|
||||
await DriveFileThumbnail.remove({
|
||||
_id: d._id
|
||||
});
|
||||
}
|
@ -6,6 +6,7 @@ import monkDb, { nativeDbConn } from '../db/mongodb';
|
||||
import Note, { deleteNote } from './note';
|
||||
import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
|
||||
import User from './user';
|
||||
import DriveFileThumbnail, { deleteDriveFileThumbnail } from './drive-file-thumbnail';
|
||||
|
||||
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
||||
DriveFile.createIndex('metadata.uri', { sparse: true, unique: true });
|
||||
@ -13,7 +14,7 @@ export default DriveFile;
|
||||
|
||||
export const DriveFileChunk = monkDb.get('driveFiles.chunks');
|
||||
|
||||
const getGridFSBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||
export const getDriveFileBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||
const db = await nativeDbConn();
|
||||
const bucket = new mongo.GridFSBucket(db, {
|
||||
bucketName: 'driveFiles'
|
||||
@ -21,8 +22,6 @@ const getGridFSBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||
return bucket;
|
||||
};
|
||||
|
||||
export { getGridFSBucket };
|
||||
|
||||
export type IMetadata = {
|
||||
properties: any;
|
||||
userId: mongo.ObjectID;
|
||||
@ -93,6 +92,11 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv
|
||||
}
|
||||
}
|
||||
|
||||
// このDriveFileのDriveFileThumbnailをすべて削除
|
||||
await Promise.all((
|
||||
await DriveFileThumbnail.find({ 'metadata.originalId': d._id })
|
||||
).map(x => deleteDriveFileThumbnail(x)));
|
||||
|
||||
// このDriveFileのチャンクをすべて削除
|
||||
await DriveFileChunk.remove({
|
||||
files_id: d._id
|
||||
|
@ -17,7 +17,7 @@ export interface INoteReaction {
|
||||
reaction: string;
|
||||
}
|
||||
|
||||
export const validateReaction = $().string().or([
|
||||
export const validateReaction = $.str.or([
|
||||
'like',
|
||||
'love',
|
||||
'laugh',
|
||||
|
@ -9,7 +9,7 @@ import Note from '../../../../models/note';
|
||||
*/
|
||||
module.exports = params => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
|
||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const datas = await Note
|
||||
|
@ -9,7 +9,7 @@ import User from '../../../../models/user';
|
||||
*/
|
||||
module.exports = params => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
|
||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const users = await User
|
||||
|
@ -12,11 +12,11 @@ import Note from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
|
||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -10,7 +10,7 @@ import FollowedLog from '../../../../../models/followed-log';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -10,7 +10,7 @@ import FollowingLog from '../../../../../models/following-log';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -13,7 +13,7 @@ import Reaction from '../../../../../models/note-reaction';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -67,24 +67,24 @@ import App, { isValidNameId, pack } from '../../../../models/app';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).get();
|
||||
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().get();
|
||||
const [name, nameErr] = $.str.get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'description' parameter
|
||||
const [description, descriptionErr] = $(params.description).string().get();
|
||||
const [description, descriptionErr] = $.str.get(params.description);
|
||||
if (descriptionErr) return rej('invalid description param');
|
||||
|
||||
// Get 'permission' parameter
|
||||
const [permission, permissionErr] = $(params.permission).array($().string()).unique().get();
|
||||
const [permission, permissionErr] = $.arr($.str).unique().get(params.permission);
|
||||
if (permissionErr) return rej('invalid permission param');
|
||||
|
||||
// Get 'callbackUrl' parameter
|
||||
// TODO: Check it is valid url
|
||||
const [callbackUrl = null, callbackUrlErr] = $(params.callbackUrl).optional.nullable.string().get();
|
||||
const [callbackUrl = null, callbackUrlErr] = $.str.optional().nullable().get(params.callbackUrl);
|
||||
if (callbackUrlErr) return rej('invalid callbackUrl param');
|
||||
|
||||
// Generate secret
|
||||
|
@ -42,7 +42,7 @@ import { isValidNameId } from '../../../../../models/app';
|
||||
*/
|
||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).get();
|
||||
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get exist
|
||||
|
@ -41,11 +41,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
// Get 'appId' parameter
|
||||
const [appId, appIdErr] = $(params.appId).optional.type(ID).get();
|
||||
const [appId, appIdErr] = $.type(ID).optional().get(params.appId);
|
||||
if (appIdErr) return rej('invalid appId param');
|
||||
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).optional.string().get();
|
||||
const [nameId, nameIdErr] = $.str.optional().get(params.nameId);
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
if (appId === undefined && nameId === undefined) {
|
||||
|
@ -40,7 +40,7 @@ import AccessToken from '../../../../models/access-token';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = $(params.token).string().get();
|
||||
const [token, tokenErr] = $.str.get(params.token);
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Fetch token
|
||||
|
@ -46,7 +46,7 @@ import config from '../../../../../config';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'appSecret' parameter
|
||||
const [appSecret, appSecretErr] = $(params.appSecret).string().get();
|
||||
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
||||
if (appSecretErr) return rej('invalid appSecret param');
|
||||
|
||||
// Lookup app
|
||||
|
@ -53,7 +53,7 @@ import AuthSess, { pack } from '../../../../../models/auth-session';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = $(params.token).string().get();
|
||||
const [token, tokenErr] = $.str.get(params.token);
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Lookup session
|
||||
|
@ -51,7 +51,7 @@ import { pack } from '../../../../../models/user';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'appSecret' parameter
|
||||
const [appSecret, appSecretErr] = $(params.appSecret).string().get();
|
||||
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
||||
if (appSecretErr) return rej('invalid appSecret param');
|
||||
|
||||
// Lookup app
|
||||
@ -64,7 +64,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = $(params.token).string().get();
|
||||
const [token, tokenErr] = $.str.get(params.token);
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Fetch token
|
||||
|
@ -13,15 +13,15 @@ import Channel, { pack } from '../../../models/channel';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -11,7 +11,7 @@ import { pack } from '../../../../models/channel';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'title' parameter
|
||||
const [title, titleErr] = $(params.title).string().range(1, 100).get();
|
||||
const [title, titleErr] = $.str.range(1, 100).get(params.title);
|
||||
if (titleErr) return rej('invalid title param');
|
||||
|
||||
// Create a channel
|
||||
|
@ -10,15 +10,15 @@ import Note, { pack } from '../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 1000, limitErr] = $(params.limit).optional.number().range(1, 1000).get();
|
||||
const [limit = 1000, limitErr] = $.num.optional().range(1, 1000).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
|
||||
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
|
@ -9,7 +9,7 @@ import Channel, { IChannel, pack } from '../../../../models/channel';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
|
||||
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
|
@ -10,7 +10,7 @@ import Watching from '../../../../models/channel-watching';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
|
||||
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
|
@ -10,7 +10,7 @@ import Watching from '../../../../models/channel-watching';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
|
||||
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
|
@ -9,15 +9,15 @@ import DriveFile, { pack } from '../../../../models/drive-file';
|
||||
*/
|
||||
module.exports = async (params, user, app) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
@ -26,11 +26,11 @@ module.exports = async (params, user, app) => {
|
||||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).get();
|
||||
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
||||
if (typeErr) throw 'invalid type param';
|
||||
|
||||
// Construct query
|
||||
|
@ -29,7 +29,7 @@ module.exports = async (file, params, user): Promise<any> => {
|
||||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
try {
|
||||
|
@ -9,11 +9,11 @@ import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().get();
|
||||
const [name, nameErr] = $.str.get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Issue query
|
||||
|
@ -9,7 +9,7 @@ import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
*/
|
||||
module.exports = async (params, user) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).type(ID).get();
|
||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||
if (fileIdErr) throw 'invalid fileId param';
|
||||
|
||||
// Fetch file
|
||||
|
@ -11,7 +11,7 @@ import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).type(ID).get();
|
||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
// Fetch file
|
||||
@ -26,12 +26,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).get();
|
||||
const [name, nameErr] = $.str.optional().pipe(validateFileName).get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) file.filename = name;
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
if (folderId !== undefined) {
|
||||
|
@ -11,11 +11,11 @@ import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
||||
module.exports = async (params, user): Promise<any> => {
|
||||
// Get 'url' parameter
|
||||
// TODO: Validate this url
|
||||
const [url, urlErr] = $(params.url).string().get();
|
||||
const [url, urlErr] = $.str.get(params.url);
|
||||
if (urlErr) throw 'invalid url param';
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
return pack(await uploadFromUrl(url, user, folderId));
|
||||
|
@ -9,15 +9,15 @@ import DriveFolder, { pack } from '../../../../models/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
@ -26,7 +26,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Construct query
|
||||
|
@ -10,11 +10,11 @@ import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).get();
|
||||
const [name = '無題のフォルダー', nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
|
||||
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// If the parent folder is specified
|
||||
|
@ -9,11 +9,11 @@ import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().get();
|
||||
const [name, nameErr] = $.str.get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
|
||||
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// Issue query
|
||||
|
@ -9,7 +9,7 @@ import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).type(ID).get();
|
||||
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Get folder
|
||||
|
@ -10,7 +10,7 @@ import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).type(ID).get();
|
||||
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Fetch folder
|
||||
@ -25,12 +25,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).optional.string().pipe(isValidFolderName).get();
|
||||
const [name, nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) folder.name = name;
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
|
||||
const [parentId, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
if (parentId !== undefined) {
|
||||
if (parentId === null) {
|
||||
|
@ -9,15 +9,15 @@ import DriveFile, { pack } from '../../../../models/drive-file';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
@ -26,7 +26,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).get();
|
||||
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
||||
if (typeErr) return rej('invalid type param');
|
||||
|
||||
// Construct query
|
||||
|
@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
|
@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the followee is yourself
|
||||
|
@ -8,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch following
|
||||
|
@ -8,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch following
|
||||
|
@ -7,7 +7,7 @@ import User from '../../../../../models/user';
|
||||
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = $(params.token).string().get();
|
||||
const [token, tokenErr] = $.str.get(params.token);
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
const _token = token.replace(/\s/g, '');
|
||||
|
@ -10,7 +10,7 @@ import config from '../../../../../config';
|
||||
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'password' parameter
|
||||
const [password, passwordErr] = $(params.password).string().get();
|
||||
const [password, passwordErr] = $.str.get(params.password);
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
|
@ -7,7 +7,7 @@ import User from '../../../../../models/user';
|
||||
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'password' parameter
|
||||
const [password, passwordErr] = $(params.password).string().get();
|
||||
const [password, passwordErr] = $.str.get(params.password);
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
|
@ -10,15 +10,15 @@ import { pack } from '../../../../models/app';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
|
||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').get();
|
||||
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Get tokens
|
||||
|
@ -10,11 +10,11 @@ import User from '../../../../models/user';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'currentPasword' parameter
|
||||
const [currentPassword, currentPasswordErr] = $(params.currentPasword).string().get();
|
||||
const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
|
||||
if (currentPasswordErr) return rej('invalid currentPasword param');
|
||||
|
||||
// Get 'newPassword' parameter
|
||||
const [newPassword, newPasswordErr] = $(params.newPassword).string().get();
|
||||
const [newPassword, newPasswordErr] = $.str.get(params.newPassword);
|
||||
if (newPasswordErr) return rej('invalid newPassword param');
|
||||
|
||||
// Compare password
|
||||
|
@ -9,15 +9,15 @@ import Favorite, { pack } from '../../../../models/favorite';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -14,27 +14,27 @@ import read from '../../common/read-notification';
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'following' parameter
|
||||
const [following = false, followingError] =
|
||||
$(params.following).optional.boolean().get();
|
||||
$.bool.optional().get(params.following);
|
||||
if (followingError) return rej('invalid following param');
|
||||
|
||||
// Get 'markAsRead' parameter
|
||||
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().get();
|
||||
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
|
||||
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = $(params.type).optional.array($().string()).unique().get();
|
||||
const [type, typeErr] = $.arr($.str).optional().unique().get(params.type);
|
||||
if (typeErr) return rej('invalid type param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -11,7 +11,7 @@ import { pack } from '../../../../models/user';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Fetch pinee
|
||||
|
@ -12,7 +12,7 @@ import generateUserToken from '../../common/generate-native-user-token';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'password' parameter
|
||||
const [password, passwordErr] = $(params.password).string().get();
|
||||
const [password, passwordErr] = $.str.get(params.password);
|
||||
if (passwordErr) return rej('invalid password param');
|
||||
|
||||
// Compare password
|
||||
|
@ -9,15 +9,15 @@ import Signin, { pack } from '../../../../models/signin';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -12,42 +12,42 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).optional.nullable.string().pipe(isValidName).get();
|
||||
const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) user.name = name;
|
||||
|
||||
// Get 'description' parameter
|
||||
const [description, descriptionErr] = $(params.description).optional.nullable.string().pipe(isValidDescription).get();
|
||||
const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description);
|
||||
if (descriptionErr) return rej('invalid description param');
|
||||
if (description !== undefined) user.description = description;
|
||||
|
||||
// Get 'location' parameter
|
||||
const [location, locationErr] = $(params.location).optional.nullable.string().pipe(isValidLocation).get();
|
||||
const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location);
|
||||
if (locationErr) return rej('invalid location param');
|
||||
if (location !== undefined) user.profile.location = location;
|
||||
|
||||
// Get 'birthday' parameter
|
||||
const [birthday, birthdayErr] = $(params.birthday).optional.nullable.string().pipe(isValidBirthday).get();
|
||||
const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday);
|
||||
if (birthdayErr) return rej('invalid birthday param');
|
||||
if (birthday !== undefined) user.profile.birthday = birthday;
|
||||
|
||||
// Get 'avatarId' parameter
|
||||
const [avatarId, avatarIdErr] = $(params.avatarId).optional.type(ID).get();
|
||||
const [avatarId, avatarIdErr] = $.type(ID).optional().get(params.avatarId);
|
||||
if (avatarIdErr) return rej('invalid avatarId param');
|
||||
if (avatarId) user.avatarId = avatarId;
|
||||
|
||||
// Get 'bannerId' parameter
|
||||
const [bannerId, bannerIdErr] = $(params.bannerId).optional.type(ID).get();
|
||||
const [bannerId, bannerIdErr] = $.type(ID).optional().get(params.bannerId);
|
||||
if (bannerIdErr) return rej('invalid bannerId param');
|
||||
if (bannerId) user.bannerId = bannerId;
|
||||
|
||||
// Get 'isBot' parameter
|
||||
const [isBot, isBotErr] = $(params.isBot).optional.boolean().get();
|
||||
const [isBot, isBotErr] = $.bool.optional().get(params.isBot);
|
||||
if (isBotErr) return rej('invalid isBot param');
|
||||
if (isBot != null) user.isBot = isBot;
|
||||
|
||||
// Get 'autoWatch' parameter
|
||||
const [autoWatch, autoWatchErr] = $(params.autoWatch).optional.boolean().get();
|
||||
const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
|
||||
if (autoWatchErr) return rej('invalid autoWatch param');
|
||||
if (autoWatch != null) user.settings.autoWatch = autoWatch;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import event from '../../../../publishers/stream';
|
||||
|
||||
/**
|
||||
@ -10,11 +10,11 @@ import event from '../../../../publishers/stream';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().get();
|
||||
const [name, nameErr] = $.str.get(params.name);
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'value' parameter
|
||||
const [value, valueErr] = $(params.value).nullable.any().get();
|
||||
const [value, valueErr] = $.any.nullable().get(params.value);
|
||||
if (valueErr) return rej('invalid value param');
|
||||
|
||||
const x = {};
|
||||
|
@ -7,20 +7,22 @@ import event from '../../../../publishers/stream';
|
||||
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'home' parameter
|
||||
const [home, homeErr] = $(params.home).optional.array().each(
|
||||
$().object(true)
|
||||
.have('name', $().string())
|
||||
.have('id', $().string())
|
||||
.have('place', $().string())
|
||||
.have('data', $().object())).get();
|
||||
const [home, homeErr] = $.arr(
|
||||
$.obj.strict()
|
||||
.have('name', $.str)
|
||||
.have('id', $.str)
|
||||
.have('place', $.str)
|
||||
.have('data', $.obj))
|
||||
.optional()
|
||||
.get(params.home);
|
||||
if (homeErr) return rej('invalid home param');
|
||||
|
||||
// Get 'id' parameter
|
||||
const [id, idErr] = $(params.id).optional.string().get();
|
||||
const [id, idErr] = $.str.optional().get(params.id);
|
||||
if (idErr) return rej('invalid id param');
|
||||
|
||||
// Get 'data' parameter
|
||||
const [data, dataErr] = $(params.data).optional.object().get();
|
||||
const [data, dataErr] = $.obj.optional().get(params.data);
|
||||
if (dataErr) return rej('invalid data param');
|
||||
|
||||
if (home) {
|
||||
|
@ -7,19 +7,20 @@ import event from '../../../../publishers/stream';
|
||||
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'home' parameter
|
||||
const [home, homeErr] = $(params.home).optional.array().each(
|
||||
$().object(true)
|
||||
.have('name', $().string())
|
||||
.have('id', $().string())
|
||||
.have('data', $().object())).get();
|
||||
const [home, homeErr] = $.arr(
|
||||
$.obj.strict()
|
||||
.have('name', $.str)
|
||||
.have('id', $.str)
|
||||
.have('data', $.obj))
|
||||
.optional().get(params.home);
|
||||
if (homeErr) return rej('invalid home param');
|
||||
|
||||
// Get 'id' parameter
|
||||
const [id, idErr] = $(params.id).optional.string().get();
|
||||
const [id, idErr] = $.str.optional().get(params.id);
|
||||
if (idErr) return rej('invalid id param');
|
||||
|
||||
// Get 'data' parameter
|
||||
const [data, dataErr] = $(params.data).optional.object().get();
|
||||
const [data, dataErr] = $.obj.optional().get(params.data);
|
||||
if (dataErr) return rej('invalid data param');
|
||||
|
||||
if (home) {
|
||||
|
@ -11,7 +11,7 @@ import { pack } from '../../../../models/messaging-message';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const mute = await Mute.find({
|
||||
|
@ -16,7 +16,7 @@ import read from '../../common/read-messaging-message';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).type(ID).get();
|
||||
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch recipient
|
||||
@ -33,19 +33,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'markAsRead' parameter
|
||||
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().get();
|
||||
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
|
||||
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -19,7 +19,7 @@ import config from '../../../../../config';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).type(ID).get();
|
||||
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Myself
|
||||
@ -41,11 +41,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'text' parameter
|
||||
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).get();
|
||||
const [text, textErr] = $.str.optional().pipe(isValidText).get(params.text);
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).optional.type(ID).get();
|
||||
const [fileId, fileIdErr] = $.type(ID).optional().get(params.fileId);
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
let file = null;
|
||||
|
@ -12,7 +12,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
|
@ -12,7 +12,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).get();
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the mutee is yourself
|
||||
|
@ -11,15 +11,15 @@ import { getFriendIds } from '../../common/get-friends';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'iknow' parameter
|
||||
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().get();
|
||||
const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow);
|
||||
if (iknowErr) return rej('invalid iknow param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 30, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 30, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).get();
|
||||
const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor);
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Construct query
|
||||
|
@ -9,11 +9,11 @@ import App, { pack } from '../../../../models/app';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
|
||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
const query = {
|
||||
|
@ -9,35 +9,35 @@ import Note, { pack } from '../../../models/note';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'reply' parameter
|
||||
const [reply, replyErr] = $(params.reply).optional.boolean().get();
|
||||
const [reply, replyErr] = $.bool.optional().get(params.reply);
|
||||
if (replyErr) return rej('invalid reply param');
|
||||
|
||||
// Get 'renote' parameter
|
||||
const [renote, renoteErr] = $(params.renote).optional.boolean().get();
|
||||
const [renote, renoteErr] = $.bool.optional().get(params.renote);
|
||||
if (renoteErr) return rej('invalid renote param');
|
||||
|
||||
// Get 'media' parameter
|
||||
const [media, mediaErr] = $(params.media).optional.boolean().get();
|
||||
const [media, mediaErr] = $.bool.optional().get(params.media);
|
||||
if (mediaErr) return rej('invalid media param');
|
||||
|
||||
// Get 'poll' parameter
|
||||
const [poll, pollErr] = $(params.poll).optional.boolean().get();
|
||||
const [poll, pollErr] = $.bool.optional().get(params.poll);
|
||||
if (pollErr) return rej('invalid poll param');
|
||||
|
||||
// Get 'bot' parameter
|
||||
//const [bot, botErr] = $(params.bot).optional.boolean().get();
|
||||
//const [bot, botErr] = $.bool.optional().get(params.bot);
|
||||
//if (botErr) return rej('invalid bot param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -13,15 +13,15 @@ import Note, { pack } from '../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
|
||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Lookup note
|
||||
|
@ -14,11 +14,11 @@ import { IApp } from '../../../../models/app';
|
||||
*/
|
||||
module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||
// Get 'visibility' parameter
|
||||
const [visibility = 'public', visibilityErr] = $(params.visibility).optional.string().or(['public', 'home', 'followers', 'specified', 'private']).get();
|
||||
const [visibility = 'public', visibilityErr] = $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']).get(params.visibility);
|
||||
if (visibilityErr) return rej('invalid visibility');
|
||||
|
||||
// Get 'visibleUserIds' parameter
|
||||
const [visibleUserIds, visibleUserIdsErr] = $(params.visibleUserIds).optional.array($().type(ID)).unique().min(1).get();
|
||||
const [visibleUserIds, visibleUserIdsErr] = $.arr($.type(ID)).optional().unique().min(1).get(params.visibleUserIds);
|
||||
if (visibleUserIdsErr) return rej('invalid visibleUserIds');
|
||||
|
||||
let visibleUsers = [];
|
||||
@ -29,36 +29,36 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
||||
}
|
||||
|
||||
// Get 'text' parameter
|
||||
const [text = null, textErr] = $(params.text).optional.nullable.string().pipe(isValidText).get();
|
||||
const [text = null, textErr] = $.str.optional().nullable().pipe(isValidText).get(params.text);
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'cw' parameter
|
||||
const [cw, cwErr] = $(params.cw).optional.nullable.string().pipe(isValidCw).get();
|
||||
const [cw, cwErr] = $.str.optional().nullable().pipe(isValidCw).get(params.cw);
|
||||
if (cwErr) return rej('invalid cw');
|
||||
|
||||
// Get 'viaMobile' parameter
|
||||
const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().get();
|
||||
const [viaMobile = false, viaMobileErr] = $.bool.optional().get(params.viaMobile);
|
||||
if (viaMobileErr) return rej('invalid viaMobile');
|
||||
|
||||
// Get 'tags' parameter
|
||||
const [tags = [], tagsErr] = $(params.tags).optional.array($().string().range(1, 32)).unique().get();
|
||||
const [tags = [], tagsErr] = $.arr($.str.range(1, 32)).optional().unique().get(params.tags);
|
||||
if (tagsErr) return rej('invalid tags');
|
||||
|
||||
// Get 'geo' parameter
|
||||
const [geo, geoErr] = $(params.geo).optional.nullable.object(true)
|
||||
.have('coordinates', $().array().length(2)
|
||||
.item(0, $().number().range(-180, 180))
|
||||
.item(1, $().number().range(-90, 90)))
|
||||
.have('altitude', $().nullable.number())
|
||||
.have('accuracy', $().nullable.number())
|
||||
.have('altitudeAccuracy', $().nullable.number())
|
||||
.have('heading', $().nullable.number().range(0, 360))
|
||||
.have('speed', $().nullable.number())
|
||||
.get();
|
||||
const [geo, geoErr] = $.obj.optional().nullable().strict()
|
||||
.have('coordinates', $.arr().length(2)
|
||||
.item(0, $.num.range(-180, 180))
|
||||
.item(1, $.num.range(-90, 90)))
|
||||
.have('altitude', $.num.nullable())
|
||||
.have('accuracy', $.num.nullable())
|
||||
.have('altitudeAccuracy', $.num.nullable())
|
||||
.have('heading', $.num.nullable().range(0, 360))
|
||||
.have('speed', $.num.nullable())
|
||||
.get(params.geo);
|
||||
if (geoErr) return rej('invalid geo');
|
||||
|
||||
// Get 'mediaIds' parameter
|
||||
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array($().type(ID)).unique().range(1, 4).get();
|
||||
const [mediaIds, mediaIdsErr] = $.arr($.type(ID)).optional().unique().range(1, 4).get(params.mediaIds);
|
||||
if (mediaIdsErr) return rej('invalid mediaIds');
|
||||
|
||||
let files = [];
|
||||
@ -85,7 +85,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
||||
}
|
||||
|
||||
// Get 'renoteId' parameter
|
||||
const [renoteId, renoteIdErr] = $(params.renoteId).optional.type(ID).get();
|
||||
const [renoteId, renoteIdErr] = $.type(ID).optional().get(params.renoteId);
|
||||
if (renoteIdErr) return rej('invalid renoteId');
|
||||
|
||||
let renote: INote = null;
|
||||
@ -106,7 +106,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
||||
}
|
||||
|
||||
// Get 'replyId' parameter
|
||||
const [replyId, replyIdErr] = $(params.replyId).optional.type(ID).get();
|
||||
const [replyId, replyIdErr] = $.type(ID).optional().get(params.replyId);
|
||||
if (replyIdErr) return rej('invalid replyId');
|
||||
|
||||
let reply: INote = null;
|
||||
@ -127,7 +127,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
||||
}
|
||||
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).optional.type(ID).get();
|
||||
const [channelId, channelIdErr] = $.type(ID).optional().get(params.channelId);
|
||||
if (channelIdErr) return rej('invalid channelId');
|
||||
|
||||
let channel: IChannel = null;
|
||||
@ -168,12 +168,12 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
||||
}
|
||||
|
||||
// Get 'poll' parameter
|
||||
const [poll, pollErr] = $(params.poll).optional.object(true)
|
||||
.have('choices', $().array($().string())
|
||||
const [poll, pollErr] = $.obj.optional().strict()
|
||||
.have('choices', $.arr($.str)
|
||||
.unique()
|
||||
.range(2, 10)
|
||||
.each(c => c.length > 0 && c.length < 50))
|
||||
.get();
|
||||
.get(params.poll);
|
||||
if (pollErr) return rej('invalid poll');
|
||||
|
||||
if (poll) {
|
||||
|
@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get favoritee
|
||||
|
@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get favoritee
|
||||
|
@ -11,23 +11,23 @@ import { pack } from '../../../../models/note';
|
||||
*/
|
||||
module.exports = async (params, user, app) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
|
||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||
|
||||
// Get 'untilDate' parameter
|
||||
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
|
||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
||||
if (untilDateErr) throw 'invalid untilDate param';
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
|
@ -11,23 +11,23 @@ import { pack } from '../../../../models/note';
|
||||
*/
|
||||
module.exports = async (params, user, app) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
|
||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||
|
||||
// Get 'untilDate' parameter
|
||||
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
|
||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
||||
if (untilDateErr) throw 'invalid untilDate param';
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
|
@ -16,19 +16,19 @@ import { pack } from '../../../../models/note';
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'following' parameter
|
||||
const [following = false, followingError] =
|
||||
$(params.following).optional.boolean().get();
|
||||
$.bool.optional().get(params.following);
|
||||
if (followingError) return rej('invalid following param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
|
||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -10,11 +10,11 @@ import Note, { pack } from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
|
||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get votes
|
||||
|
@ -14,7 +14,7 @@ import notify from '../../../../../publishers/notify';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get votee
|
||||
@ -32,9 +32,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
|
||||
// Get 'choice' parameter
|
||||
const [choice, choiceError] =
|
||||
$(params.choice).number()
|
||||
$.num
|
||||
.pipe(c => note.poll.choices.some(x => x.id == c))
|
||||
.get();
|
||||
.get(params.choice);
|
||||
if (choiceError) return rej('invalid choice param');
|
||||
|
||||
// if already voted
|
||||
|
@ -14,19 +14,19 @@ import Reaction, { pack } from '../../../../models/note-reaction';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
|
||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
|
||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').get();
|
||||
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Lookup note
|
||||
|
@ -11,11 +11,11 @@ import { validateReaction } from '../../../../../models/note-reaction';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'reaction' parameter
|
||||
const [reaction, reactionErr] = $(params.reaction).string().pipe(validateReaction.ok).get();
|
||||
const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction);
|
||||
if (reactionErr) return rej('invalid reaction param');
|
||||
|
||||
// Fetch reactee
|
||||
|
@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Fetch unreactee
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user