Skip to content

Commit

Permalink
ファイルを並行してアップロードする
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 3, 2023
1 parent 4a29825 commit f7e894a
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions lib/state_notifier/note_create_page/note_create_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,41 +249,13 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
throw SpecifiedException("投票期間を入れてや");
}

if (state.files.length > 16) {
throw SpecifiedException("ファイルは16個以下にしてください");
}

try {
state = state.copyWith(isNoteSending: NoteSendStatus.sending);

final fileIds = <String>[];

for (final file in state.files) {
switch (file) {
case PostFile():
final response = await misskey.drive.files.createAsBinary(
DriveFilesCreateRequest(
force: true,
name: file.fileName,
isSensitive: file.isNsfw,
comment: file.caption,
),
await file.file.readAsBytes(),
);
fileIds.add(response.id);
case AlreadyPostedFile():
if (file.isEdited) {
await misskey.drive.files.update(
DriveFilesUpdateRequest(
fileId: file.file.id,
name: file.fileName,
isSensitive: file.isNsfw,
comment: file.caption,
),
);
}
fileIds.add(file.file.id);
}
}

if (!mounted) return;

final nodes = const MfmParser().parse(state.text);
final userList = <MfmMention>[];

Expand All @@ -306,6 +278,36 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
throw SpecifiedException("連合オフやのによそのサーバーの人がメンションに含まれてるで");
}

final fileIds = await Future.wait(
state.files.map((file) async {
switch (file) {
case PostFile():
final response = await misskey.drive.files.createAsBinary(
DriveFilesCreateRequest(
force: true,
name: file.fileName,
isSensitive: file.isNsfw,
comment: file.caption,
),
await file.file.readAsBytes(),
);
return response.id;
case AlreadyPostedFile():
if (file.isEdited) {
await misskey.drive.files.update(
DriveFilesUpdateRequest(
fileId: file.file.id,
name: file.fileName,
isSensitive: file.isNsfw,
comment: file.caption,
),
);
}
return file.file.id;
}
}),
);

final mentionTargetUsers = [
for (final user in userList)
await misskey.users.showByName(UsersShowByUserNameRequest(
Expand Down

0 comments on commit f7e894a

Please sign in to comment.