mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-01 03:41:59 +01:00
nameId廃止 & アプリ作成時にシークレットを返すように
This commit is contained in:
parent
d60c3c4ee3
commit
bb7b335491
6 changed files with 7 additions and 103 deletions
|
@ -7,7 +7,7 @@
|
|||
<div class="app">
|
||||
<section>
|
||||
<h2>{{ app.name }}</h2>
|
||||
<p class="nid">{{ app.nameId }}</p>
|
||||
<p class="id">{{ app.id }}</p>
|
||||
<p class="description">{{ app.description }}</p>
|
||||
</section>
|
||||
<section>
|
||||
|
|
|
@ -5,16 +5,6 @@
|
|||
<b-form-group label="アプリケーション名" description="あなたのアプリの名称。">
|
||||
<b-form-input v-model="name" type="text" placeholder="ex) Misskey for iOS" autocomplete="off" required/>
|
||||
</b-form-group>
|
||||
<b-form-group label="ID" description="あなたのアプリのID。">
|
||||
<b-input v-model="nid" type="text" pattern="^[a-zA-Z0-9_]{1,30}$" placeholder="ex) misskey-for-ios" autocomplete="off" required/>
|
||||
<p class="info" v-if="nidState == 'wait'" style="color:#999">%fa:spinner .pulse .fw%確認しています...</p>
|
||||
<p class="info" v-if="nidState == 'ok'" style="color:#3CB7B5">%fa:fw check%利用できます</p>
|
||||
<p class="info" v-if="nidState == 'unavailable'" style="color:#FF1161">%fa:fw exclamation-triangle%既に利用されています</p>
|
||||
<p class="info" v-if="nidState == 'error'" style="color:#FF1161">%fa:fw exclamation-triangle%通信エラー</p>
|
||||
<p class="info" v-if="nidState == 'invalid-format'" style="color:#FF1161">%fa:fw exclamation-triangle%a~z、A~Z、0~9、_が使えます</p>
|
||||
<p class="info" v-if="nidState == 'min-range'" style="color:#FF1161">%fa:fw exclamation-triangle%1文字以上でお願いします!</p>
|
||||
<p class="info" v-if="nidState == 'max-range'" style="color:#FF1161">%fa:fw exclamation-triangle%30文字以内でお願いします</p>
|
||||
</b-form-group>
|
||||
<b-form-group label="アプリの概要" description="あなたのアプリの簡単な説明や紹介。">
|
||||
<b-textarea v-model="description" placeholder="ex) Misskey iOSクライアント。" autocomplete="off" required></b-textarea>
|
||||
</b-form-group>
|
||||
|
@ -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
|
||||
|
|
|
@ -5,8 +5,6 @@ import db from '../db/mongodb';
|
|||
import config from '../config';
|
||||
|
||||
const App = db.get<IApp>('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;
|
||||
|
|
|
@ -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
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -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<any>}
|
||||
*/
|
||||
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
|
||||
});
|
||||
});
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue