リレーに不正なURLは追加できないように (#6351)

* リレーに不正なURLは追加できないように

* lint
This commit is contained in:
MeiMei 2020-05-15 20:51:16 +09:00 committed by GitHub
parent c5dd9439d5
commit 538ca2a7c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -64,6 +64,11 @@ export default Vue.extend({
inbox
}).then((relay: any) => {
this.refresh();
}).catch((e: any) => {
this.$root.dialog({
type: 'error',
text: e.message || e
});
});
},
@ -72,6 +77,11 @@ export default Vue.extend({
inbox
}).then(() => {
this.refresh();
}).catch((e: any) => {
this.$root.dialog({
type: 'error',
text: e.message || e
});
});
},

View file

@ -1,6 +1,7 @@
import $ from 'cafy';
import define from '../../../define';
import { addRelay } from '../../../../../services/relay';
import { ApiError } from '../../../error';
export const meta = {
desc: {
@ -17,8 +18,22 @@ export const meta = {
validator: $.str
},
},
errors: {
invalidUrl: {
message: 'Invalid URL',
code: 'INVALID_URL',
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c'
},
}
};
export default define(meta, async (ps, user) => {
try {
if (new URL(ps.inbox).protocol !== 'https:') throw 'https only';
} catch {
throw new ApiError(meta.errors.invalidUrl);
}
return await addRelay(ps.inbox);
});