wip: get app version from db.
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
import 'package:angel3_orm/angel3_orm.dart';
|
||||
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||
import 'package:dde_gesture_manager_api/src/models/base_model.dart';
|
||||
import 'package:angel3_migration/angel3_migration.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
part 'app_version.g.dart';
|
||||
|
||||
@serializable
|
||||
abstract class _AppVersion {
|
||||
@orm
|
||||
abstract class _AppVersion extends BaseModel {
|
||||
@SerializableField(isNullable: false)
|
||||
@Column(isNullable: false)
|
||||
String? get versionName;
|
||||
|
||||
@SerializableField(isNullable: false)
|
||||
@Column(isNullable: false)
|
||||
int? get versionCode;
|
||||
}
|
||||
|
||||
@serializable
|
||||
@Orm(tableName: 'app_versions', generateMigrations: false)
|
||||
abstract class _AppVersionResp {
|
||||
@SerializableField(isNullable: false)
|
||||
String? get versionName;
|
||||
|
||||
|
||||
@@ -3,24 +3,18 @@ import 'dart:async';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:dde_gesture_manager_api/apis.dart';
|
||||
import 'package:dde_gesture_manager_api/src/models/app_version.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
late FileSystem fs;
|
||||
import 'controller_extensions.dart';
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
app.get(
|
||||
Apis.system.appVersion,
|
||||
(req, res) async {
|
||||
var pubspec = fs.currentDirectory.parent.childDirectory('app').childFile('pubspec.yaml').readAsStringSync();
|
||||
var version = loadYaml(pubspec)['version'] as String;
|
||||
var versions = version.split('+');
|
||||
return res.json(AppVersion(versionName: versions.first, versionCode: int.parse(versions.last)));
|
||||
var appVersionQuery = AppVersionQuery();
|
||||
appVersionQuery.orderBy(AppVersionFields.versionCode, descending: true);
|
||||
return appVersionQuery.getOne(req.queryExecutor).then((value) => AppVersionResp(
|
||||
versionName: value.value.versionName,
|
||||
versionCode: value.value.versionCode,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
configureServerWithFileSystem(FileSystem fileSystem) {
|
||||
fs = fileSystem;
|
||||
return configureServer;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||
});
|
||||
|
||||
// Typically, you want to mount controllers first, after any global middleware.
|
||||
await app.configure(system_controllers.configureServerWithFileSystem(fileSystem));
|
||||
await app.configure(system_controllers.configureServer);
|
||||
await app.configure(auth_controllers.configureServer);
|
||||
await app.configure(scheme_controllers.configureServer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user