Skip to content

Commit 339132e

Browse files
committed
feat: Implement SM.MS and Imgloc picture bed configuration
This commit introduces the configuration and integration of SM.MS and Imgloc as picture bed services. - **ConfigurePictureBedPage**: - Displays the current configuration status (prepared or not prepared) for SM.MS and Imgloc. - Prompts the user to accept terms of service and privacy policy before configuring a picture bed for the first time. - Navigates to `ConfigureChevertoPage` for API key input. - Temporarily commented out SM.MS configuration. - **ConfigureChevertoPage**: - Allows users to input and save the API token for the selected Cheverto-based picture bed (Imgloc, SM.MS). - Displays links to the terms of service and privacy policy for the selected picture bed. - Uses `PlatformTextFormField` for API key input. - **CheveretoApiClient**: - Added `uploadImageToCheveretoByBinaryFile` method to support uploading images as binary files in addition to base64 strings. - **New JSON Models and API Client for SM.MS**: - `SmmsTokenResult.dart`: Defines the model for SM.MS API token responses. - `SmmsProfileResult.dart`: Defines the model for SM.MS user profile responses. - `SmmsUploadImageResult.dart`: Defines the model for SM.MS image upload responses. - `SmmsApiClient.dart`: Implements a Retrofit client for interacting with the SM.MS API (v2), including methods for getting API tokens, user profiles, and uploading images. - Corresponding `.g.dart` files generated for JSON serialization/deserialization. - **ChooseAdExemptPage**: - Updated the `PlatformElevatedButton` to use `Theme.of(context).colorScheme.primaryContainer` for its color and `Theme.of(context).colorScheme.onPrimaryContainer` for its text color.
1 parent 125a227 commit 339132e

13 files changed

+717
-49
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'SmmsProfileResult.g.dart'; // Name your file, e.g., user_profile_response.dart
4+
5+
@JsonSerializable(explicitToJson: true)
6+
class SmmsProfileResult {
7+
bool success;
8+
String code;
9+
String message;
10+
SmmsProfileData data;
11+
12+
@JsonKey(name: 'RequestId')
13+
String requestId;
14+
15+
SmmsProfileResult({
16+
required this.success,
17+
required this.code,
18+
required this.message,
19+
required this.data,
20+
required this.requestId,
21+
});
22+
23+
factory SmmsProfileResult.fromJson(Map<String, dynamic> json) =>
24+
_$SmmsProfileResultFromJson(json);
25+
26+
Map<String, dynamic> toJson() => _$SmmsProfileResultToJson(this);
27+
}
28+
29+
@JsonSerializable()
30+
class SmmsProfileData {
31+
String username;
32+
String email; // Empty string in example, so String is fine
33+
String role;
34+
35+
@JsonKey(name: 'group_expire')
36+
String groupExpire; // "0000-00-00", could be DateTime with a converter if needed
37+
38+
@JsonKey(name: 'email_verified')
39+
int emailVerified; // 0 or 1, could be bool with a converter
40+
41+
@JsonKey(name: 'disk_usage')
42+
String diskUsage; // e.g., "2.58 MB"
43+
44+
@JsonKey(name: 'disk_limit')
45+
String diskLimit; // e.g., "50.00 GB"
46+
47+
@JsonKey(name: 'disk_usage_raw')
48+
int diskUsageRaw; // Raw bytes
49+
50+
@JsonKey(name: 'disk_limit_raw')
51+
int diskLimitRaw; // Raw bytes
52+
53+
SmmsProfileData({
54+
required this.username,
55+
required this.email,
56+
required this.role,
57+
required this.groupExpire,
58+
required this.emailVerified,
59+
required this.diskUsage,
60+
required this.diskLimit,
61+
required this.diskUsageRaw,
62+
required this.diskLimitRaw,
63+
});
64+
65+
factory SmmsProfileData.fromJson(Map<String, dynamic> json) =>
66+
_$SmmsProfileDataFromJson(json);
67+
68+
Map<String, dynamic> toJson() => _$SmmsProfileDataToJson(this);
69+
}

lib/JsonResult/SmmsProfileResult.g.dart

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'SmmsTokenResult.g.dart'; // Name your file, e.g., api_token_response.dart
4+
5+
@JsonSerializable(explicitToJson: true) // Good practice for nested objects
6+
class SmmsTokenResult {
7+
bool success;
8+
String code;
9+
String message;
10+
SmmsTokenData data;
11+
12+
@JsonKey(name: 'RequestId') // Matches the JSON key capitalization
13+
String requestId;
14+
15+
SmmsTokenResult({
16+
required this.success,
17+
required this.code,
18+
required this.message,
19+
required this.data,
20+
required this.requestId,
21+
});
22+
23+
factory SmmsTokenResult.fromJson(Map<String, dynamic> json) =>
24+
_$SmmsTokenResultFromJson(json);
25+
26+
Map<String, dynamic> toJson() => _$SmmsTokenResultToJson(this);
27+
}
28+
29+
@JsonSerializable()
30+
class SmmsTokenData {
31+
String token;
32+
33+
SmmsTokenData({
34+
required this.token,
35+
});
36+
37+
factory SmmsTokenData.fromJson(Map<String, dynamic> json) =>
38+
_$SmmsTokenDataFromJson(json);
39+
40+
Map<String, dynamic> toJson() => _$SmmsTokenDataToJson(this);
41+
}

lib/JsonResult/SmmsTokenResult.g.dart

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'SmmsUploadImageResult.g.dart'; // Name your file, e.g., smms_upload_response.dart
4+
5+
@JsonSerializable(explicitToJson: true)
6+
class SmmsUploadImageResult {
7+
bool success;
8+
String code;
9+
String message;
10+
SmmsUploadImageData data;
11+
12+
@JsonKey(name: 'RequestId')
13+
String requestId;
14+
15+
SmmsUploadImageResult({
16+
required this.success,
17+
required this.code,
18+
required this.message,
19+
required this.data,
20+
required this.requestId,
21+
});
22+
23+
factory SmmsUploadImageResult.fromJson(Map<String, dynamic> json) =>
24+
_$SmmsUploadImageResultFromJson(json);
25+
26+
Map<String, dynamic> toJson() => _$SmmsUploadImageResultToJson(this);
27+
}
28+
29+
@JsonSerializable()
30+
class SmmsUploadImageData {
31+
@JsonKey(name: 'file_id')
32+
int fileId; // Assuming it's always an int, even if 0
33+
34+
int width;
35+
int height;
36+
String filename;
37+
String storename;
38+
int size;
39+
String path;
40+
String hash;
41+
String url;
42+
String delete;
43+
String page;
44+
45+
SmmsUploadImageData({
46+
required this.fileId,
47+
required this.width,
48+
required this.height,
49+
required this.filename,
50+
required this.storename,
51+
required this.size,
52+
required this.path,
53+
required this.hash,
54+
required this.url,
55+
required this.delete,
56+
required this.page,
57+
});
58+
59+
factory SmmsUploadImageData.fromJson(Map<String, dynamic> json) =>
60+
_$SmmsUploadImageDataFromJson(json);
61+
62+
Map<String, dynamic> toJson() => _$SmmsUploadImageDataToJson(this);
63+
}

lib/JsonResult/SmmsUploadImageResult.g.dart

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/client/CheveretoApiClient.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:dio/dio.dart' hide Headers;
24
import 'package:discuz_flutter/JsonResult/ChevertoUploadResult.dart';
35
import 'package:retrofit/error_logger.dart';
@@ -11,8 +13,15 @@ abstract class CheveretoApiClient {
1113

1214
@POST("/api/1/upload/")
1315
@FormUrlEncoded()
14-
Future<ChevertoUploadResult> uploadImageToChevereto(
16+
Future<ChevertoUploadResult> uploadImageToCheveretoByBase64(
1517
@Header("X-API-Key") String apiToken,
1618
@Field("source") String base64String,
1719
);
20+
21+
@POST("/api/1/upload/")
22+
@FormUrlEncoded()
23+
Future<ChevertoUploadResult> uploadImageToCheveretoByBinaryFile(
24+
@Header("X-API-Key") String apiToken,
25+
@Part() File source,
26+
);
1827
}

0 commit comments

Comments
 (0)