Skip to content

Commit

Permalink
Merge pull request #58 from poppingmoon/drive-usage
Browse files Browse the repository at this point in the history
driveに対応
  • Loading branch information
shiosyakeyakini-info authored Oct 18, 2024
2 parents 45745b7 + ef56d14 commit 161518b
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/misskey_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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';
Expand Down
15 changes: 15 additions & 0 deletions lib/src/data/drive/drive_response.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json) =>
_$DriveResponseFromJson(json);
}
170 changes: 170 additions & 0 deletions lib/src/data/drive/drive_response.freezed.dart
Original file line number Diff line number Diff line change
@@ -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>(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<String, dynamic> json) {
return _DriveResponse.fromJson(json);
}

/// @nodoc
mixin _$DriveResponse {
int get capacity => throw _privateConstructorUsedError;
int get usage => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$DriveResponseCopyWith<DriveResponse> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) =
_$DriveResponseImpl.fromJson;

@override
int get capacity;
@override
int get usage;
@override
@JsonKey(ignore: true)
_$$DriveResponseImplCopyWith<_$DriveResponseImpl> get copyWith =>
throw _privateConstructorUsedError;
}
19 changes: 19 additions & 0 deletions lib/src/data/drive/drive_response.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/src/misskey_drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class MisskeyDrive {
: files = MisskeyDriveFiles(_apiService),
folders = MisskeyDriveFolders(_apiService);

/// ドライブの容量と使用量を取得します。
Future<DriveResponse> drive() async {
final response = await _apiService.post<Map<String, dynamic>>("drive", {});
return DriveResponse.fromJson(response);
}

/// ドライブにあるファイルの一覧を取得します。
Future<Iterable<DriveFile>> stream(DriveStreamRequest request) async {
final response =
Expand Down
4 changes: 4 additions & 0 deletions test/misskey_drive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 161518b

Please sign in to comment.