From ef56d14f22db072eb79747b19a3071b259034425 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Thu, 11 Apr 2024 06:27:10 +0900 Subject: [PATCH] =?UTF-8?q?drive=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/misskey_dart.dart | 1 + lib/src/data/drive/drive_response.dart | 15 ++ .../data/drive/drive_response.freezed.dart | 170 ++++++++++++++++++ lib/src/data/drive/drive_response.g.dart | 19 ++ lib/src/misskey_drive.dart | 6 + test/misskey_drive_test.dart | 4 + 6 files changed, 215 insertions(+) create mode 100644 lib/src/data/drive/drive_response.dart create mode 100644 lib/src/data/drive/drive_response.freezed.dart create mode 100644 lib/src/data/drive/drive_response.g.dart diff --git a/lib/misskey_dart.dart b/lib/misskey_dart.dart index a286fa42..5c6b3d5a 100644 --- a/lib/misskey_dart.dart +++ b/lib/misskey_dart.dart @@ -77,6 +77,7 @@ export 'src/data/clips/clips_unfavorite_request.dart'; export 'src/data/clips/clips_update_request.dart'; export 'src/data/drive/drive_files_request.dart'; export 'src/data/drive/drive_folders_request.dart'; +export 'src/data/drive/drive_response.dart'; export 'src/data/drive/drive_stream_request.dart'; export 'src/data/drive/files/drive_files_attached_notes_request.dart'; export 'src/data/drive/files/drive_files_check_existence_request.dart'; diff --git a/lib/src/data/drive/drive_response.dart b/lib/src/data/drive/drive_response.dart new file mode 100644 index 00000000..4416a53b --- /dev/null +++ b/lib/src/data/drive/drive_response.dart @@ -0,0 +1,15 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'drive_response.freezed.dart'; +part 'drive_response.g.dart'; + +@freezed +class DriveResponse with _$DriveResponse { + const factory DriveResponse({ + required int capacity, + required int usage, + }) = _DriveResponse; + + factory DriveResponse.fromJson(Map json) => + _$DriveResponseFromJson(json); +} diff --git a/lib/src/data/drive/drive_response.freezed.dart b/lib/src/data/drive/drive_response.freezed.dart new file mode 100644 index 00000000..de4f6ecb --- /dev/null +++ b/lib/src/data/drive/drive_response.freezed.dart @@ -0,0 +1,170 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'drive_response.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +DriveResponse _$DriveResponseFromJson(Map json) { + return _DriveResponse.fromJson(json); +} + +/// @nodoc +mixin _$DriveResponse { + int get capacity => throw _privateConstructorUsedError; + int get usage => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $DriveResponseCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DriveResponseCopyWith<$Res> { + factory $DriveResponseCopyWith( + DriveResponse value, $Res Function(DriveResponse) then) = + _$DriveResponseCopyWithImpl<$Res, DriveResponse>; + @useResult + $Res call({int capacity, int usage}); +} + +/// @nodoc +class _$DriveResponseCopyWithImpl<$Res, $Val extends DriveResponse> + implements $DriveResponseCopyWith<$Res> { + _$DriveResponseCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? capacity = null, + Object? usage = null, + }) { + return _then(_value.copyWith( + capacity: null == capacity + ? _value.capacity + : capacity // ignore: cast_nullable_to_non_nullable + as int, + usage: null == usage + ? _value.usage + : usage // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$DriveResponseImplCopyWith<$Res> + implements $DriveResponseCopyWith<$Res> { + factory _$$DriveResponseImplCopyWith( + _$DriveResponseImpl value, $Res Function(_$DriveResponseImpl) then) = + __$$DriveResponseImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({int capacity, int usage}); +} + +/// @nodoc +class __$$DriveResponseImplCopyWithImpl<$Res> + extends _$DriveResponseCopyWithImpl<$Res, _$DriveResponseImpl> + implements _$$DriveResponseImplCopyWith<$Res> { + __$$DriveResponseImplCopyWithImpl( + _$DriveResponseImpl _value, $Res Function(_$DriveResponseImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? capacity = null, + Object? usage = null, + }) { + return _then(_$DriveResponseImpl( + capacity: null == capacity + ? _value.capacity + : capacity // ignore: cast_nullable_to_non_nullable + as int, + usage: null == usage + ? _value.usage + : usage // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$DriveResponseImpl implements _DriveResponse { + const _$DriveResponseImpl({required this.capacity, required this.usage}); + + factory _$DriveResponseImpl.fromJson(Map json) => + _$$DriveResponseImplFromJson(json); + + @override + final int capacity; + @override + final int usage; + + @override + String toString() { + return 'DriveResponse(capacity: $capacity, usage: $usage)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$DriveResponseImpl && + (identical(other.capacity, capacity) || + other.capacity == capacity) && + (identical(other.usage, usage) || other.usage == usage)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, capacity, usage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$DriveResponseImplCopyWith<_$DriveResponseImpl> get copyWith => + __$$DriveResponseImplCopyWithImpl<_$DriveResponseImpl>(this, _$identity); + + @override + Map toJson() { + return _$$DriveResponseImplToJson( + this, + ); + } +} + +abstract class _DriveResponse implements DriveResponse { + const factory _DriveResponse( + {required final int capacity, + required final int usage}) = _$DriveResponseImpl; + + factory _DriveResponse.fromJson(Map json) = + _$DriveResponseImpl.fromJson; + + @override + int get capacity; + @override + int get usage; + @override + @JsonKey(ignore: true) + _$$DriveResponseImplCopyWith<_$DriveResponseImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/data/drive/drive_response.g.dart b/lib/src/data/drive/drive_response.g.dart new file mode 100644 index 00000000..0957f819 --- /dev/null +++ b/lib/src/data/drive/drive_response.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'drive_response.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$DriveResponseImpl _$$DriveResponseImplFromJson(Map json) => + _$DriveResponseImpl( + capacity: json['capacity'] as int, + usage: json['usage'] as int, + ); + +Map _$$DriveResponseImplToJson(_$DriveResponseImpl instance) => + { + 'capacity': instance.capacity, + 'usage': instance.usage, + }; diff --git a/lib/src/misskey_drive.dart b/lib/src/misskey_drive.dart index 8d7b561e..fcbc32f8 100644 --- a/lib/src/misskey_drive.dart +++ b/lib/src/misskey_drive.dart @@ -13,6 +13,12 @@ class MisskeyDrive { : files = MisskeyDriveFiles(_apiService), folders = MisskeyDriveFolders(_apiService); + /// ドライブの容量と使用量を取得します。 + Future drive() async { + final response = await _apiService.post>("drive", {}); + return DriveResponse.fromJson(response); + } + /// ドライブにあるファイルの一覧を取得します。 Future> stream(DriveStreamRequest request) async { final response = diff --git a/test/misskey_drive_test.dart b/test/misskey_drive_test.dart index 5f5b35c0..5c91c6f9 100644 --- a/test/misskey_drive_test.dart +++ b/test/misskey_drive_test.dart @@ -8,6 +8,10 @@ import 'package:uuid/uuid.dart'; import 'util/misskey_dart_test_util.dart'; void main() async { + test("drive", () async { + await userClient.drive.drive(); + }); + test("stream", () async { final file = await userClient.createDriveFile(); final response = await userClient.drive.stream(DriveStreamRequest());