Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
feature(Model): Define profile
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgeass committed Jul 22, 2021
1 parent f97069b commit 3d222e4
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is a generated file; do not edit or check into version control.
path_provider=C:\\Users\\linqihang\\scoop\\apps\\flutter\\current\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider-2.0.2\\
path_provider_linux=C:\\Users\\linqihang\\scoop\\apps\\flutter\\current\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_linux-2.0.0\\
path_provider_macos=C:\\Users\\linqihang\\scoop\\apps\\flutter\\current\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_macos-2.0.0\\
path_provider_windows=C:\\Users\\linqihang\\scoop\\apps\\flutter\\current\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_windows-2.0.1\\
1 change: 1 addition & 0 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider","path":"C:\\\\Users\\\\linqihang\\\\scoop\\\\apps\\\\flutter\\\\current\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.2\\\\","dependencies":[]}],"android":[{"name":"path_provider","path":"C:\\\\Users\\\\linqihang\\\\scoop\\\\apps\\\\flutter\\\\current\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\Users\\\\linqihang\\\\scoop\\\\apps\\\\flutter\\\\current\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.0\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\linqihang\\\\scoop\\\\apps\\\\flutter\\\\current\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.0.0\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\linqihang\\\\scoop\\\\apps\\\\flutter\\\\current\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.1\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2021-07-22 18:40:13.592612","version":"2.2.1"}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ doc/api/
*.js_
*.js.deps
*.js.map

.idea
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# keylol_flutter
keylol.com mobile flutter client

# API 列表

* /api/mobile/index.php?version=4&module=profile

用户信息

* /api/mobile/index.php?version=4&module=viewthread&tid=?&page=?

帖子

* /api/mobile/index.php?version=4&module=sendreply&action=reply&replysubmit=yes&fid=?&tid=?

回复

message:
posttime:
formhash:
usesig:
1 change: 1 addition & 0 deletions keylol_flutter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
32 changes: 32 additions & 0 deletions lib/common/keylol_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:async';

import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:keylol_flutter/model/profile.dart';
import 'package:path_provider/path_provider.dart';

class KeylolClient {
static late Dio _dio;

static Future<void> init() async {
_dio = Dio(BaseOptions(
baseUrl: "https://keylol.com", queryParameters: {'version': 4}));

var appDocDir = await getApplicationDocumentsDirectory();
var appDocPath = appDocDir.path;

var cj = PersistCookieJar(
ignoreExpires: false, storage: FileStorage(appDocPath + "/.cookies/"));
_dio.interceptors.add(CookieManager(cj));
}

Future<Profile> fetchProfile() async {
var res = await _dio
.get("/api/mobile/index.php", queryParameters: {'module': 'profile'});
if (res.statusCode != 200) {
Future.error(res.data);
}
return Profile.fromJson(res.data['Variables']);
}
}
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:keylol_flutter/common/keylol_client.dart';

void main() {
runApp(MyApp());
Future.any([
KeylolClient.init(),
]).then((value) => runApp(MyApp()));
}

class MyApp extends StatelessWidget {
Expand Down
93 changes: 93 additions & 0 deletions lib/model/profile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class Profile {
String? cookiePre;
String? auth;
String? saltKey;
int? memberUid;
String? memberUsername;
String? memberAvatar;
int? groupId;
String? formHash;
String? isModerator;
int? readAccess;
Notice? notice;

Profile(
this.cookiePre,
this.auth,
this.saltKey,
this.memberUid,
this.memberUsername,
this.memberAvatar,
this.groupId,
this.formHash,
this.isModerator,
this.readAccess,
this.notice);

Profile.fromJson(Map<String, dynamic> json) {
cookiePre = json['cookiepre'];
auth = json['auth'];
saltKey = json['saltkey'];
String? memberUidStr = json['memberuid'];
if (memberUidStr != null) {
memberUid = int.parse(memberUidStr);
}
memberUsername = json['memberusername'];
memberAvatar = json['memberavatar'];
String? groupIdStr = json['groupid'];
if (groupIdStr != null) {
groupId = int.parse(groupIdStr);
}
formHash = json['formhash'];
isModerator = json['ismoderator'];
String? readAccessStr = json['readaccess'];
if (readAccessStr != null) {
readAccess = int.parse(readAccessStr);
}
Map<String, dynamic>? noticeJson = json['notice'];
if (noticeJson != null) {
notice = Notice.fromJson(noticeJson);
}
}

Map<String, dynamic> toJson() {
Map<String, dynamic> data = new Map<String, dynamic>();
data['cookiepre'] = this.cookiePre;
data['auth'] = this.auth;
data['saltkey'] = this.saltKey;
data['memberuid'] = this.memberUid?.toString();
data['memberusername'] = this.memberUsername?.toString();
data['memberavatar'] = this.memberAvatar?.toString();
data['groupid'] = this.groupId?.toString();
data['formhash'] = this.formHash;
data['ismoderator'] = this.isModerator;
data['readaccess'] = this.readAccess?.toString();
data['notice'] = this.notice?.toJson();
return data;
}
}

class Notice {
int? newPush;
int? newPm;
int? newPrompt;
int? newMyPost;

Notice(this.newPush, this.newPm, this.newPrompt, this.newMyPost);

Notice.fromJson(Map<String, dynamic> json) {
newPush = json['newpush'];
newPm = json['newpm'];
newPrompt = json['newprompt'];
newMyPost = json['newmypost'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['newpush'] = this.newPush;
data['newpm'] = this.newPm;
data['newprompt'] = this.newPrompt;
data['newmypost'] = this.newMyPost;
return data;
}
}
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dio: ^4.0.0
dio_cookie_manager: ^2.0.0
path_provider: ^2.0.2
cookie_jar: ^3.0.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 3d222e4

Please sign in to comment.