mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 23:25:13 +00:00
parent
0fff2e4f16
commit
ce0d4f77fa
6 changed files with 105 additions and 0 deletions
|
@ -706,6 +706,7 @@ common/views/components/profile-editor.vue:
|
||||||
following-list: "フォロー"
|
following-list: "フォロー"
|
||||||
mute-list: "ミュート"
|
mute-list: "ミュート"
|
||||||
blocking-list: "ブロック"
|
blocking-list: "ブロック"
|
||||||
|
user-lists: "リスト"
|
||||||
export-requested: "エクスポートをリクエストしました。これには時間がかかる場合があります。エクスポートが終わると、ドライブにファイルが追加されます。"
|
export-requested: "エクスポートをリクエストしました。これには時間がかかる場合があります。エクスポートが終わると、ドライブにファイルが追加されます。"
|
||||||
enter-password: "パスワードを入力してください"
|
enter-password: "パスワードを入力してください"
|
||||||
danger-zone: "危険な設定"
|
danger-zone: "危険な設定"
|
||||||
|
|
|
@ -97,6 +97,7 @@
|
||||||
<option value="following">{{ $t('export-targets.following-list') }}</option>
|
<option value="following">{{ $t('export-targets.following-list') }}</option>
|
||||||
<option value="mute">{{ $t('export-targets.mute-list') }}</option>
|
<option value="mute">{{ $t('export-targets.mute-list') }}</option>
|
||||||
<option value="blocking">{{ $t('export-targets.blocking-list') }}</option>
|
<option value="blocking">{{ $t('export-targets.blocking-list') }}</option>
|
||||||
|
<option value="user-lists">{{ $t('export-targets.user-lists') }}</option>
|
||||||
</ui-select>
|
</ui-select>
|
||||||
<ui-button @click="doExport()"><fa :icon="faDownload"/> {{ $t('export') }}</ui-button>
|
<ui-button @click="doExport()"><fa :icon="faDownload"/> {{ $t('export') }}</ui-button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -284,6 +285,7 @@ export default Vue.extend({
|
||||||
this.exportTarget == 'following' ? 'i/export-following' :
|
this.exportTarget == 'following' ? 'i/export-following' :
|
||||||
this.exportTarget == 'mute' ? 'i/export-mute' :
|
this.exportTarget == 'mute' ? 'i/export-mute' :
|
||||||
this.exportTarget == 'blocking' ? 'i/export-blocking' :
|
this.exportTarget == 'blocking' ? 'i/export-blocking' :
|
||||||
|
this.exportTarget == 'user-lists' ? 'i/export-user-lists' :
|
||||||
null, {});
|
null, {});
|
||||||
|
|
||||||
this.$root.dialog({
|
this.$root.dialog({
|
||||||
|
|
|
@ -136,6 +136,15 @@ export function createExportBlockingJob(user: ILocalUser) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createExportUserListsJob(user: ILocalUser) {
|
||||||
|
return dbQueue.add('exportUserLists', {
|
||||||
|
user: user
|
||||||
|
}, {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
if (!program.onlyServer) {
|
if (!program.onlyServer) {
|
||||||
deliverQueue.process(128, processDeliver);
|
deliverQueue.process(128, processDeliver);
|
||||||
|
|
73
src/queue/processors/db/export-user-lists.ts
Normal file
73
src/queue/processors/db/export-user-lists.ts
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import * as Bull from 'bull';
|
||||||
|
import * as tmp from 'tmp';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as mongo from 'mongodb';
|
||||||
|
|
||||||
|
import { queueLogger } from '../../logger';
|
||||||
|
import addFile from '../../../services/drive/add-file';
|
||||||
|
import User from '../../../models/user';
|
||||||
|
import dateFormat = require('dateformat');
|
||||||
|
import config from '../../../config';
|
||||||
|
import UserList from '../../../models/user-list';
|
||||||
|
|
||||||
|
const logger = queueLogger.createSubLogger('export-user-lists');
|
||||||
|
|
||||||
|
export async function exportUserLists(job: Bull.Job, done: any): Promise<void> {
|
||||||
|
logger.info(`Exporting user lists of ${job.data.user._id} ...`);
|
||||||
|
|
||||||
|
const user = await User.findOne({
|
||||||
|
_id: new mongo.ObjectID(job.data.user._id.toString())
|
||||||
|
});
|
||||||
|
|
||||||
|
const lists = await UserList.find({
|
||||||
|
userId: user._id
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create temp file
|
||||||
|
const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
||||||
|
tmp.file((e, path, fd, cleanup) => {
|
||||||
|
if (e) return rej(e);
|
||||||
|
res([path, cleanup]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info(`Temp file is ${path}`);
|
||||||
|
|
||||||
|
const stream = fs.createWriteStream(path, { flags: 'a' });
|
||||||
|
|
||||||
|
for (const list of lists) {
|
||||||
|
const users = await User.find({
|
||||||
|
_id: { $in: list.userIds }
|
||||||
|
}, {
|
||||||
|
fields: {
|
||||||
|
username: true,
|
||||||
|
host: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const u of users) {
|
||||||
|
const acct = u.host ? `${u.username}@${u.host}` : `${u.username}@${config.host}`;
|
||||||
|
const content = `${list.title},${acct}`;
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
stream.write(content + '\n', err => {
|
||||||
|
if (err) {
|
||||||
|
logger.error(err);
|
||||||
|
rej(err);
|
||||||
|
} else {
|
||||||
|
res();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.end();
|
||||||
|
logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
|
const fileName = 'user-lists-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv';
|
||||||
|
const driveFile = await addFile(user, path, fileName);
|
||||||
|
|
||||||
|
logger.succ(`Exported to: ${driveFile._id}`);
|
||||||
|
cleanup();
|
||||||
|
done();
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import { exportNotes } from './export-notes';
|
||||||
import { exportFollowing } from './export-following';
|
import { exportFollowing } from './export-following';
|
||||||
import { exportMute } from './export-mute';
|
import { exportMute } from './export-mute';
|
||||||
import { exportBlocking } from './export-blocking';
|
import { exportBlocking } from './export-blocking';
|
||||||
|
import { exportUserLists } from './export-user-lists';
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
deleteNotes,
|
deleteNotes,
|
||||||
|
@ -13,6 +14,7 @@ const jobs = {
|
||||||
exportFollowing,
|
exportFollowing,
|
||||||
exportMute,
|
exportMute,
|
||||||
exportBlocking,
|
exportBlocking,
|
||||||
|
exportUserLists
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
export default function(dbQueue: Bull.Queue) {
|
export default function(dbQueue: Bull.Queue) {
|
||||||
|
|
18
src/server/api/endpoints/i/export-user-lists.ts
Normal file
18
src/server/api/endpoints/i/export-user-lists.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import define from '../../define';
|
||||||
|
import { createExportUserListsJob } from '../../../../queue';
|
||||||
|
import ms = require('ms');
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
secure: true,
|
||||||
|
requireCredential: true,
|
||||||
|
limit: {
|
||||||
|
duration: ms('1min'),
|
||||||
|
max: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, async (ps, user) => {
|
||||||
|
createExportUserListsJob(user);
|
||||||
|
|
||||||
|
return;
|
||||||
|
});
|
Loading…
Reference in a new issue