Skip to content

Commit

Permalink
Merge pull request yojo-art#12 from team-shahu/feat/avatar-decoration…
Browse files Browse the repository at this point in the history
…s-add-button

feat: アバターデコレーションをmisskeyUIから追加できるように
  • Loading branch information
chan-mai authored Jun 14, 2024
2 parents dcba2ce + 98ec2e4 commit 6c0021a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- 二要素認証のバックアップコードを保存するように促すダイアログを表示するように
- カスタムフォント機能
- 絵文字を登録したユーザーがアカウントを消去しても継続して絵文字の使用ができるように
- アバターデコレーションを登録したユーザーがアカウントを消去しても継続して使用ができるように
- アバターデコレーションをmisskeyUI上から登録できるように

## Special Thanks
- [Misskey](https://github.com/misskey-dev/misskey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
import { DriveService } from '@/core/DriveService.js';

export const meta = {
tags: ['admin'],
Expand All @@ -32,12 +33,19 @@ export const paramDef = {
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
private avatarDecorationService: AvatarDecorationService,
private driveService: DriveService,
) {
super(meta, paramDef, async (ps, me) => {
// システムユーザーとして再アップロード
const sysFileData = await this.driveService.uploadFromUrl({
url: ps.url,
user: null,
force: true,
});
await this.avatarDecorationService.create({
name: ps.name,
description: ps.description,
url: ps.url,
url: sysFileData.url,
roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration,
}, me);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
import { DriveService } from '@/core/DriveService.js';
import { ApiError } from '../../../error.js';

export const meta = {
Expand Down Expand Up @@ -38,12 +39,24 @@ export const paramDef = {
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
private avatarDecorationService: AvatarDecorationService,
private driveService: DriveService,
) {
super(meta, paramDef, async (ps, me) => {
let fileUrl = ps.url;
// URLに変更があるか
if (typeof ps.url !== 'undefined' || typeof ps.url === 'string' ) {
// システムユーザーとして再アップロード
const sysFileData = await this.driveService.uploadFromUrl({
url: ps.url,
user: null,
force: true,
});
fileUrl = sysFileData.url;
}
await this.avatarDecorationService.update(ps.id, {
name: ps.name,
description: ps.description,
url: ps.url,
url: fileUrl,
roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration,
}, me);
});
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend/src/pages/avatar-decorations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #caption>{{ avatarDecoration.description }}</template>

<div class="_gaps_m">
<MkButton rounded style="margin: 0 auto;" @click="selectImage(avatarDecoration, $event)">{{ i18n.ts.selectFile }}</MkButton>
<MkInput v-model="avatarDecoration.name">
<template #label>{{ i18n.ts.name }}</template>
</MkInput>
Expand Down Expand Up @@ -44,9 +45,17 @@ import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkFolder from '@/components/MkFolder.vue';
import { selectFile } from '@/scripts/select-file.js';

const avatarDecorations = ref<Misskey.entities.AdminAvatarDecorationsListResponse>([]);

// ファイル選択
async function selectImage(decoration, ev) {
let file = await selectFile(ev.currentTarget ?? ev.target, null);
decoration.name = file.name.replace(/\.(.+)$/, '');
decoration.url = file.url;
}

function add() {
avatarDecorations.value.unshift({
_id: Math.random().toString(36),
Expand Down

0 comments on commit 6c0021a

Please sign in to comment.