From eaa3cbc9ab44bc719c1a1184bde3d0ffd67f027e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Aug 2018 18:38:02 +0900 Subject: [PATCH] =?UTF-8?q?nameId=E5=BB=83=E6=AD=A2=20&=20=E3=82=A2?= =?UTF-8?q?=E3=83=97=E3=83=AA=E4=BD=9C=E6=88=90=E6=99=82=E3=81=AB=E3=82=B7?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=AC=E3=83=83=E3=83=88=E3=82=92=E8=BF=94?= =?UTF-8?q?=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/app/auth/views/form.vue | 2 +- src/client/app/dev/views/new-app.vue | 41 ------------------- src/models/app.ts | 10 ----- src/server/api/endpoints/app/create.ts | 12 ++---- .../api/endpoints/app/name_id/available.ts | 31 -------------- src/server/api/endpoints/app/show.ts | 14 +------ 6 files changed, 7 insertions(+), 103 deletions(-) delete mode 100644 src/server/api/endpoints/app/name_id/available.ts diff --git a/src/client/app/auth/views/form.vue b/src/client/app/auth/views/form.vue index 2d1e6d3e8..d18a4f7eb 100644 --- a/src/client/app/auth/views/form.vue +++ b/src/client/app/auth/views/form.vue @@ -7,7 +7,7 @@

{{ app.name }}

-

{{ app.nameId }}

+

{{ app.id }}

{{ app.description }}

diff --git a/src/client/app/dev/views/new-app.vue b/src/client/app/dev/views/new-app.vue index 87b35db25..7321df00c 100644 --- a/src/client/app/dev/views/new-app.vue +++ b/src/client/app/dev/views/new-app.vue @@ -5,16 +5,6 @@ - - -

%fa:spinner .pulse .fw%確認しています...

-

%fa:fw check%利用できます

-

%fa:fw exclamation-triangle%既に利用されています

-

%fa:fw exclamation-triangle%通信エラー

-

%fa:fw exclamation-triangle%a~z、A~Z、0~9、_が使えます

-

%fa:fw exclamation-triangle%1文字以上でお願いします!

-

%fa:fw exclamation-triangle%30文字以内でお願いします

-
@@ -50,47 +40,16 @@ export default Vue.extend({ data() { return { name: '', - nid: '', description: '', cb: '', nidState: null, permission: [] }; }, - watch: { - nid() { - if (this.nid == null || this.nid == '') { - this.nidState = null; - return; - } - - const err = - !this.nid.match(/^[a-zA-Z0-9_]+$/) ? 'invalid-format' : - this.nid.length < 1 ? 'min-range' : - this.nid.length > 30 ? 'max-range' : - null; - - if (err) { - this.nidState = err; - return; - } - - this.nidState = 'wait'; - - (this as any).api('app/name_id/available', { - nameId: this.nid - }).then(result => { - this.nidState = result.available ? 'ok' : 'unavailable'; - }).catch(err => { - this.nidState = 'error'; - }); - } - }, methods: { onSubmit() { (this as any).api('app/create', { name: this.name, - nameId: this.nid, description: this.description, callbackUrl: this.cb, permission: this.permission diff --git a/src/models/app.ts b/src/models/app.ts index 01cc946c6..c0b2b5a0f 100644 --- a/src/models/app.ts +++ b/src/models/app.ts @@ -5,8 +5,6 @@ import db from '../db/mongodb'; import config from '../config'; const App = db.get('apps'); -App.createIndex('nameId'); -App.createIndex('nameIdLower'); App.createIndex('secret'); export default App; @@ -16,17 +14,11 @@ export type IApp = { userId: mongo.ObjectID | null; secret: string; name: string; - nameId: string; - nameIdLower: string; description: string; permission: string[]; callbackUrl: string; }; -export function isValidNameId(nameId: string): boolean { - return typeof nameId == 'string' && /^[a-zA-Z0-9_]{1,30}$/.test(nameId); -} - /** * Pack an app for API response * @@ -76,8 +68,6 @@ export const pack = ( _app.id = _app._id; delete _app._id; - delete _app.nameIdLower; - // Visible by only owner if (!opts.includeSecret) { delete _app.secret; diff --git a/src/server/api/endpoints/app/create.ts b/src/server/api/endpoints/app/create.ts index b2a5fb73c..afe3ab35a 100644 --- a/src/server/api/endpoints/app/create.ts +++ b/src/server/api/endpoints/app/create.ts @@ -1,6 +1,6 @@ import rndstr from 'rndstr'; import $ from 'cafy'; -import App, { isValidNameId, pack } from '../../../../models/app'; +import App, { pack } from '../../../../models/app'; import { ILocalUser } from '../../../../models/user'; export const meta = { @@ -11,10 +11,6 @@ export const meta = { * Create an app */ export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { - // Get 'nameId' parameter - const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId); - if (nameIdErr) return rej('invalid nameId param'); - // Get 'name' parameter const [name, nameErr] = $.str.get(params.name); if (nameErr) return rej('invalid name param'); @@ -40,8 +36,6 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res, createdAt: new Date(), userId: user && user._id, name: name, - nameId: nameId, - nameIdLower: nameId.toLowerCase(), description: description, permission: permission, callbackUrl: callbackUrl, @@ -49,5 +43,7 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res, }); // Response - res(await pack(app)); + res(await pack(app, null, { + includeSecret: true + })); }); diff --git a/src/server/api/endpoints/app/name_id/available.ts b/src/server/api/endpoints/app/name_id/available.ts deleted file mode 100644 index 2cd56e92d..000000000 --- a/src/server/api/endpoints/app/name_id/available.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import App from '../../../../../models/app'; -import { isValidNameId } from '../../../../../models/app'; - -/** - * Check available nameId of app - * - * @param {any} params - * @return {Promise} - */ -export default async (params: any) => new Promise(async (res, rej) => { - // Get 'nameId' parameter - const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId); - if (nameIdErr) return rej('invalid nameId param'); - - // Get exist - const exist = await App - .count({ - nameIdLower: nameId.toLowerCase() - }, { - limit: 1 - }); - - // Reply - res({ - available: exist === 0 - }); -}); diff --git a/src/server/api/endpoints/app/show.ts b/src/server/api/endpoints/app/show.ts index 6668d0f24..072fbaeb7 100644 --- a/src/server/api/endpoints/app/show.ts +++ b/src/server/api/endpoints/app/show.ts @@ -9,21 +9,11 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( const isSecure = user != null && app == null; // Get 'appId' parameter - const [appId, appIdErr] = $.type(ID).optional.get(params.appId); + const [appId, appIdErr] = $.type(ID).get(params.appId); if (appIdErr) return rej('invalid appId param'); - // Get 'nameId' parameter - const [nameId, nameIdErr] = $.str.optional.get(params.nameId); - if (nameIdErr) return rej('invalid nameId param'); - - if (appId === undefined && nameId === undefined) { - return rej('appId or nameId is required'); - } - // Lookup app - const ap = appId !== undefined - ? await App.findOne({ _id: appId }) - : await App.findOne({ nameIdLower: nameId.toLowerCase() }); + const ap = await App.findOne({ _id: appId }); if (ap === null) { return rej('app not found');