Skip to content

An open-source cross-platform alternative to AirDrop

refactor: web state

Tien Do Nam224ef8b16ac5
diff --git a/app/lib/model/state/send/web/web_send_file.dart b/app/lib/model/state/send/web/web_download_file.dart
similarity index 79%
rename from app/lib/model/state/send/web/web_send_file.dart
rename to app/lib/model/state/send/web/web_download_file.dart
index fff839c4..fc5cee78 100644
--- a/app/lib/model/state/send/web/web_send_file.dart
+++ b/app/lib/model/state/send/web/web_download_file.dart
@@ -2,16 +2,16 @@ import 'package:dart_mappable/dart_mappable.dart';
import 'package:localsend_isolates/model/dto/file_dto.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
-part 'web_send_file.mapper.dart';
+part 'web_download_file.mapper.dart';
@MappableClass()
-class WebSendFile with WebSendFileMappable {
+class WebDownloadFile with WebDownloadFileMappable {
final FileDto file;
final AssetEntity? asset; // for thumbnails
final String? path; // android, iOS, desktop
final List<int>? bytes; // web
- const WebSendFile({
+ const WebDownloadFile({
required this.file,
required this.asset,
required this.path,
diff --git a/app/lib/model/state/send/web/web_download_file.mapper.dart b/app/lib/model/state/send/web/web_download_file.mapper.dart
new file mode 100644
index 00000000..00888ea6
--- /dev/null
+++ b/app/lib/model/state/send/web/web_download_file.mapper.dart
@@ -0,0 +1,170 @@
+// coverage:ignore-file
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// dart format off
+// ignore_for_file: type=lint
+// ignore_for_file: invalid_use_of_protected_member
+// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
+// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
+
+part of 'web_download_file.dart';
+
+class WebDownloadFileMapper extends ClassMapperBase<WebDownloadFile> {
+ WebDownloadFileMapper._();
+
+ static WebDownloadFileMapper? _instance;
+ static WebDownloadFileMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebDownloadFileMapper._());
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebDownloadFile';
+
+ static FileDto _$file(WebDownloadFile v) => v.file;
+ static const Field<WebDownloadFile, FileDto> _f$file = Field('file', _$file);
+ static AssetEntity? _$asset(WebDownloadFile v) => v.asset;
+ static const Field<WebDownloadFile, AssetEntity> _f$asset = Field(
+ 'asset',
+ _$asset,
+ );
+ static String? _$path(WebDownloadFile v) => v.path;
+ static const Field<WebDownloadFile, String> _f$path = Field('path', _$path);
+ static List<int>? _$bytes(WebDownloadFile v) => v.bytes;
+ static const Field<WebDownloadFile, List<int>> _f$bytes = Field(
+ 'bytes',
+ _$bytes,
+ );
+
+ @override
+ final MappableFields<WebDownloadFile> fields = const {
+ #file: _f$file,
+ #asset: _f$asset,
+ #path: _f$path,
+ #bytes: _f$bytes,
+ };
+
+ static WebDownloadFile _instantiate(DecodingData data) {
+ return WebDownloadFile(
+ file: data.dec(_f$file),
+ asset: data.dec(_f$asset),
+ path: data.dec(_f$path),
+ bytes: data.dec(_f$bytes),
+ );
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebDownloadFile fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebDownloadFile>(map);
+ }
+
+ static WebDownloadFile deserialize(String json) {
+ return ensureInitialized().decodeJson<WebDownloadFile>(json);
+ }
+}
+
+mixin WebDownloadFileMappable {
+ String serialize() {
+ return WebDownloadFileMapper.ensureInitialized()
+ .encodeJson<WebDownloadFile>(this as WebDownloadFile);
+ }
+
+ Map<String, dynamic> toJson() {
+ return WebDownloadFileMapper.ensureInitialized().encodeMap<WebDownloadFile>(
+ this as WebDownloadFile,
+ );
+ }
+
+ WebDownloadFileCopyWith<WebDownloadFile, WebDownloadFile, WebDownloadFile>
+ get copyWith =>
+ _WebDownloadFileCopyWithImpl<WebDownloadFile, WebDownloadFile>(
+ this as WebDownloadFile,
+ $identity,
+ $identity,
+ );
+ @override
+ String toString() {
+ return WebDownloadFileMapper.ensureInitialized().stringifyValue(
+ this as WebDownloadFile,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return WebDownloadFileMapper.ensureInitialized().equalsValue(
+ this as WebDownloadFile,
+ other,
+ );
+ }
+
+ @override
+ int get hashCode {
+ return WebDownloadFileMapper.ensureInitialized().hashValue(
+ this as WebDownloadFile,
+ );
+ }
+}
+
+extension WebDownloadFileValueCopy<$R, $Out>
+ on ObjectCopyWith<$R, WebDownloadFile, $Out> {
+ WebDownloadFileCopyWith<$R, WebDownloadFile, $Out> get $asWebDownloadFile =>
+ $base.as((v, t, t2) => _WebDownloadFileCopyWithImpl<$R, $Out>(v, t, t2));
+}
+
+abstract class WebDownloadFileCopyWith<$R, $In extends WebDownloadFile, $Out>
+ implements ClassCopyWith<$R, $In, $Out> {
+ ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>>? get bytes;
+ $R call({FileDto? file, AssetEntity? asset, String? path, List<int>? bytes});
+ WebDownloadFileCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ );
+}
+
+class _WebDownloadFileCopyWithImpl<$R, $Out>
+ extends ClassCopyWithBase<$R, WebDownloadFile, $Out>
+ implements WebDownloadFileCopyWith<$R, WebDownloadFile, $Out> {
+ _WebDownloadFileCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<WebDownloadFile> $mapper =
+ WebDownloadFileMapper.ensureInitialized();
+ @override
+ ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>>? get bytes =>
+ $value.bytes != null
+ ? ListCopyWith(
+ $value.bytes!,
+ (v, t) => ObjectCopyWith(v, $identity, t),
+ (v) => call(bytes: v),
+ )
+ : null;
+ @override
+ $R call({
+ FileDto? file,
+ Object? asset = $none,
+ Object? path = $none,
+ Object? bytes = $none,
+ }) => $apply(
+ FieldCopyWithData({
+ if (file != null) #file: file,
+ if (asset != $none) #asset: asset,
+ if (path != $none) #path: path,
+ if (bytes != $none) #bytes: bytes,
+ }),
+ );
+ @override
+ WebDownloadFile $make(CopyWithData data) => WebDownloadFile(
+ file: data.get(#file, or: $value.file),
+ asset: data.get(#asset, or: $value.asset),
+ path: data.get(#path, or: $value.path),
+ bytes: data.get(#bytes, or: $value.bytes),
+ );
+
+ @override
+ WebDownloadFileCopyWith<$R2, WebDownloadFile, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ ) => _WebDownloadFileCopyWithImpl<$R2, $Out2>($value, $cast, t);
+}
+
diff --git a/app/lib/model/state/send/web/web_send_session.dart b/app/lib/model/state/send/web/web_download_session.dart
similarity index 74%
rename from app/lib/model/state/send/web/web_send_session.dart
rename to app/lib/model/state/send/web/web_download_session.dart
index c7a129bd..10a82000 100644
--- a/app/lib/model/state/send/web/web_send_session.dart
+++ b/app/lib/model/state/send/web/web_download_session.dart
@@ -1,15 +1,15 @@
import 'package:dart_mappable/dart_mappable.dart';
-part 'web_send_session.mapper.dart';
+part 'web_download_session.mapper.dart';
@MappableClass()
-class WebSendSession with WebSendSessionMappable {
+class WebDownloadSession with WebDownloadSessionMappable {
final String sessionId;
final bool pending; // true while waiting for the user to accept or reject the request
final String ip;
final String deviceInfo; // parsed from userAgent
- const WebSendSession({
+ const WebDownloadSession({
required this.sessionId,
required this.pending,
required this.ip,
diff --git a/app/lib/model/state/send/web/web_download_session.mapper.dart b/app/lib/model/state/send/web/web_download_session.mapper.dart
new file mode 100644
index 00000000..6533c94d
--- /dev/null
+++ b/app/lib/model/state/send/web/web_download_session.mapper.dart
@@ -0,0 +1,168 @@
+// coverage:ignore-file
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// dart format off
+// ignore_for_file: type=lint
+// ignore_for_file: invalid_use_of_protected_member
+// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
+// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
+
+part of 'web_download_session.dart';
+
+class WebDownloadSessionMapper extends ClassMapperBase<WebDownloadSession> {
+ WebDownloadSessionMapper._();
+
+ static WebDownloadSessionMapper? _instance;
+ static WebDownloadSessionMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebDownloadSessionMapper._());
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebDownloadSession';
+
+ static String _$sessionId(WebDownloadSession v) => v.sessionId;
+ static const Field<WebDownloadSession, String> _f$sessionId = Field(
+ 'sessionId',
+ _$sessionId,
+ );
+ static bool _$pending(WebDownloadSession v) => v.pending;
+ static const Field<WebDownloadSession, bool> _f$pending = Field(
+ 'pending',
+ _$pending,
+ );
+ static String _$ip(WebDownloadSession v) => v.ip;
+ static const Field<WebDownloadSession, String> _f$ip = Field('ip', _$ip);
+ static String _$deviceInfo(WebDownloadSession v) => v.deviceInfo;
+ static const Field<WebDownloadSession, String> _f$deviceInfo = Field(
+ 'deviceInfo',
+ _$deviceInfo,
+ );
+
+ @override
+ final MappableFields<WebDownloadSession> fields = const {
+ #sessionId: _f$sessionId,
+ #pending: _f$pending,
+ #ip: _f$ip,
+ #deviceInfo: _f$deviceInfo,
+ };
+
+ static WebDownloadSession _instantiate(DecodingData data) {
+ return WebDownloadSession(
+ sessionId: data.dec(_f$sessionId),
+ pending: data.dec(_f$pending),
+ ip: data.dec(_f$ip),
+ deviceInfo: data.dec(_f$deviceInfo),
+ );
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebDownloadSession fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebDownloadSession>(map);
+ }
+
+ static WebDownloadSession deserialize(String json) {
+ return ensureInitialized().decodeJson<WebDownloadSession>(json);
+ }
+}
+
+mixin WebDownloadSessionMappable {
+ String serialize() {
+ return WebDownloadSessionMapper.ensureInitialized()
+ .encodeJson<WebDownloadSession>(this as WebDownloadSession);
+ }
+
+ Map<String, dynamic> toJson() {
+ return WebDownloadSessionMapper.ensureInitialized()
+ .encodeMap<WebDownloadSession>(this as WebDownloadSession);
+ }
+
+ WebDownloadSessionCopyWith<
+ WebDownloadSession,
+ WebDownloadSession,
+ WebDownloadSession
+ >
+ get copyWith =>
+ _WebDownloadSessionCopyWithImpl<WebDownloadSession, WebDownloadSession>(
+ this as WebDownloadSession,
+ $identity,
+ $identity,
+ );
+ @override
+ String toString() {
+ return WebDownloadSessionMapper.ensureInitialized().stringifyValue(
+ this as WebDownloadSession,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return WebDownloadSessionMapper.ensureInitialized().equalsValue(
+ this as WebDownloadSession,
+ other,
+ );
+ }
+
+ @override
+ int get hashCode {
+ return WebDownloadSessionMapper.ensureInitialized().hashValue(
+ this as WebDownloadSession,
+ );
+ }
+}
+
+extension WebDownloadSessionValueCopy<$R, $Out>
+ on ObjectCopyWith<$R, WebDownloadSession, $Out> {
+ WebDownloadSessionCopyWith<$R, WebDownloadSession, $Out>
+ get $asWebDownloadSession => $base.as(
+ (v, t, t2) => _WebDownloadSessionCopyWithImpl<$R, $Out>(v, t, t2),
+ );
+}
+
+abstract class WebDownloadSessionCopyWith<
+ $R,
+ $In extends WebDownloadSession,
+ $Out
+>
+ implements ClassCopyWith<$R, $In, $Out> {
+ $R call({String? sessionId, bool? pending, String? ip, String? deviceInfo});
+ WebDownloadSessionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ );
+}
+
+class _WebDownloadSessionCopyWithImpl<$R, $Out>
+ extends ClassCopyWithBase<$R, WebDownloadSession, $Out>
+ implements WebDownloadSessionCopyWith<$R, WebDownloadSession, $Out> {
+ _WebDownloadSessionCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<WebDownloadSession> $mapper =
+ WebDownloadSessionMapper.ensureInitialized();
+ @override
+ $R call({String? sessionId, bool? pending, String? ip, String? deviceInfo}) =>
+ $apply(
+ FieldCopyWithData({
+ if (sessionId != null) #sessionId: sessionId,
+ if (pending != null) #pending: pending,
+ if (ip != null) #ip: ip,
+ if (deviceInfo != null) #deviceInfo: deviceInfo,
+ }),
+ );
+ @override
+ WebDownloadSession $make(CopyWithData data) => WebDownloadSession(
+ sessionId: data.get(#sessionId, or: $value.sessionId),
+ pending: data.get(#pending, or: $value.pending),
+ ip: data.get(#ip, or: $value.ip),
+ deviceInfo: data.get(#deviceInfo, or: $value.deviceInfo),
+ );
+
+ @override
+ WebDownloadSessionCopyWith<$R2, WebDownloadSession, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ ) => _WebDownloadSessionCopyWithImpl<$R2, $Out2>($value, $cast, t);
+}
+
diff --git a/app/lib/model/state/send/web/web_download_state.dart b/app/lib/model/state/send/web/web_download_state.dart
new file mode 100644
index 00000000..434cfdf3
--- /dev/null
+++ b/app/lib/model/state/send/web/web_download_state.dart
@@ -0,0 +1,23 @@
+import 'package:dart_mappable/dart_mappable.dart';
+import 'package:localsend_app/model/state/send/web/web_download_file.dart';
+import 'package:localsend_app/model/state/send/web/web_download_session.dart';
+
+part 'web_download_state.mapper.dart';
+
+@MappableClass()
+class WebDownloadState with WebDownloadStateMappable {
+ final Map<String, WebDownloadSession> sessions; // session id -> session data, also includes incoming requests
+ final Map<String, WebDownloadFile> files; // file id as key
+ final bool autoAccept; // automatically accept incoming requests
+
+ const WebDownloadState({
+ required this.sessions,
+ required this.files,
+ required this.autoAccept,
+ });
+
+ @override
+ String toString() {
+ return 'WebDownloadState(sessions: $sessions, files: <${files.keys}>, autoAccept: $autoAccept)';
+ }
+}
diff --git a/app/lib/model/state/send/web/web_download_state.mapper.dart b/app/lib/model/state/send/web/web_download_state.mapper.dart
new file mode 100644
index 00000000..1c9853f6
--- /dev/null
+++ b/app/lib/model/state/send/web/web_download_state.mapper.dart
@@ -0,0 +1,197 @@
+// coverage:ignore-file
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// dart format off
+// ignore_for_file: type=lint
+// ignore_for_file: invalid_use_of_protected_member
+// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
+// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
+
+part of 'web_download_state.dart';
+
+class WebDownloadStateMapper extends ClassMapperBase<WebDownloadState> {
+ WebDownloadStateMapper._();
+
+ static WebDownloadStateMapper? _instance;
+ static WebDownloadStateMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebDownloadStateMapper._());
+ WebDownloadSessionMapper.ensureInitialized();
+ WebDownloadFileMapper.ensureInitialized();
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebDownloadState';
+
+ static Map<String, WebDownloadSession> _$sessions(WebDownloadState v) =>
+ v.sessions;
+ static const Field<WebDownloadState, Map<String, WebDownloadSession>>
+ _f$sessions = Field('sessions', _$sessions);
+ static Map<String, WebDownloadFile> _$files(WebDownloadState v) => v.files;
+ static const Field<WebDownloadState, Map<String, WebDownloadFile>> _f$files =
+ Field('files', _$files);
+ static bool _$autoAccept(WebDownloadState v) => v.autoAccept;
+ static const Field<WebDownloadState, bool> _f$autoAccept = Field(
+ 'autoAccept',
+ _$autoAccept,
+ );
+
+ @override
+ final MappableFields<WebDownloadState> fields = const {
+ #sessions: _f$sessions,
+ #files: _f$files,
+ #autoAccept: _f$autoAccept,
+ };
+
+ static WebDownloadState _instantiate(DecodingData data) {
+ return WebDownloadState(
+ sessions: data.dec(_f$sessions),
+ files: data.dec(_f$files),
+ autoAccept: data.dec(_f$autoAccept),
+ );
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebDownloadState fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebDownloadState>(map);
+ }
+
+ static WebDownloadState deserialize(String json) {
+ return ensureInitialized().decodeJson<WebDownloadState>(json);
+ }
+}
+
+mixin WebDownloadStateMappable {
+ String serialize() {
+ return WebDownloadStateMapper.ensureInitialized()
+ .encodeJson<WebDownloadState>(this as WebDownloadState);
+ }
+
+ Map<String, dynamic> toJson() {
+ return WebDownloadStateMapper.ensureInitialized()
+ .encodeMap<WebDownloadState>(this as WebDownloadState);
+ }
+
+ WebDownloadStateCopyWith<WebDownloadState, WebDownloadState, WebDownloadState>
+ get copyWith =>
+ _WebDownloadStateCopyWithImpl<WebDownloadState, WebDownloadState>(
+ this as WebDownloadState,
+ $identity,
+ $identity,
+ );
+ @override
+ String toString() {
+ return WebDownloadStateMapper.ensureInitialized().stringifyValue(
+ this as WebDownloadState,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return WebDownloadStateMapper.ensureInitialized().equalsValue(
+ this as WebDownloadState,
+ other,
+ );
+ }
+
+ @override
+ int get hashCode {
+ return WebDownloadStateMapper.ensureInitialized().hashValue(
+ this as WebDownloadState,
+ );
+ }
+}
+
+extension WebDownloadStateValueCopy<$R, $Out>
+ on ObjectCopyWith<$R, WebDownloadState, $Out> {
+ WebDownloadStateCopyWith<$R, WebDownloadState, $Out>
+ get $asWebDownloadState =>
+ $base.as((v, t, t2) => _WebDownloadStateCopyWithImpl<$R, $Out>(v, t, t2));
+}
+
+abstract class WebDownloadStateCopyWith<$R, $In extends WebDownloadState, $Out>
+ implements ClassCopyWith<$R, $In, $Out> {
+ MapCopyWith<
+ $R,
+ String,
+ WebDownloadSession,
+ WebDownloadSessionCopyWith<$R, WebDownloadSession, WebDownloadSession>
+ >
+ get sessions;
+ MapCopyWith<
+ $R,
+ String,
+ WebDownloadFile,
+ WebDownloadFileCopyWith<$R, WebDownloadFile, WebDownloadFile>
+ >
+ get files;
+ $R call({
+ Map<String, WebDownloadSession>? sessions,
+ Map<String, WebDownloadFile>? files,
+ bool? autoAccept,
+ });
+ WebDownloadStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ );
+}
+
+class _WebDownloadStateCopyWithImpl<$R, $Out>
+ extends ClassCopyWithBase<$R, WebDownloadState, $Out>
+ implements WebDownloadStateCopyWith<$R, WebDownloadState, $Out> {
+ _WebDownloadStateCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<WebDownloadState> $mapper =
+ WebDownloadStateMapper.ensureInitialized();
+ @override
+ MapCopyWith<
+ $R,
+ String,
+ WebDownloadSession,
+ WebDownloadSessionCopyWith<$R, WebDownloadSession, WebDownloadSession>
+ >
+ get sessions => MapCopyWith(
+ $value.sessions,
+ (v, t) => v.copyWith.$chain(t),
+ (v) => call(sessions: v),
+ );
+ @override
+ MapCopyWith<
+ $R,
+ String,
+ WebDownloadFile,
+ WebDownloadFileCopyWith<$R, WebDownloadFile, WebDownloadFile>
+ >
+ get files => MapCopyWith(
+ $value.files,
+ (v, t) => v.copyWith.$chain(t),
+ (v) => call(files: v),
+ );
+ @override
+ $R call({
+ Map<String, WebDownloadSession>? sessions,
+ Map<String, WebDownloadFile>? files,
+ bool? autoAccept,
+ }) => $apply(
+ FieldCopyWithData({
+ if (sessions != null) #sessions: sessions,
+ if (files != null) #files: files,
+ if (autoAccept != null) #autoAccept: autoAccept,
+ }),
+ );
+ @override
+ WebDownloadState $make(CopyWithData data) => WebDownloadState(
+ sessions: data.get(#sessions, or: $value.sessions),
+ files: data.get(#files, or: $value.files),
+ autoAccept: data.get(#autoAccept, or: $value.autoAccept),
+ );
+
+ @override
+ WebDownloadStateCopyWith<$R2, WebDownloadState, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ ) => _WebDownloadStateCopyWithImpl<$R2, $Out2>($value, $cast, t);
+}
+
diff --git a/app/lib/model/state/send/web/web_send_file.mapper.dart b/app/lib/model/state/send/web/web_send_file.mapper.dart
deleted file mode 100644
index 765b1e28..00000000
--- a/app/lib/model/state/send/web/web_send_file.mapper.dart
+++ /dev/null
@@ -1,163 +0,0 @@
-// coverage:ignore-file
-// GENERATED CODE - DO NOT MODIFY BY HAND
-// dart format off
-// ignore_for_file: type=lint
-// ignore_for_file: invalid_use_of_protected_member
-// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
-// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
-
-part of 'web_send_file.dart';
-
-class WebSendFileMapper extends ClassMapperBase<WebSendFile> {
- WebSendFileMapper._();
-
- static WebSendFileMapper? _instance;
- static WebSendFileMapper ensureInitialized() {
- if (_instance == null) {
- MapperContainer.globals.use(_instance = WebSendFileMapper._());
- }
- return _instance!;
- }
-
- @override
- final String id = 'WebSendFile';
-
- static FileDto _$file(WebSendFile v) => v.file;
- static const Field<WebSendFile, FileDto> _f$file = Field('file', _$file);
- static AssetEntity? _$asset(WebSendFile v) => v.asset;
- static const Field<WebSendFile, AssetEntity> _f$asset = Field(
- 'asset',
- _$asset,
- );
- static String? _$path(WebSendFile v) => v.path;
- static const Field<WebSendFile, String> _f$path = Field('path', _$path);
- static List<int>? _$bytes(WebSendFile v) => v.bytes;
- static const Field<WebSendFile, List<int>> _f$bytes = Field('bytes', _$bytes);
-
- @override
- final MappableFields<WebSendFile> fields = const {
- #file: _f$file,
- #asset: _f$asset,
- #path: _f$path,
- #bytes: _f$bytes,
- };
-
- static WebSendFile _instantiate(DecodingData data) {
- return WebSendFile(
- file: data.dec(_f$file),
- asset: data.dec(_f$asset),
- path: data.dec(_f$path),
- bytes: data.dec(_f$bytes),
- );
- }
-
- @override
- final Function instantiate = _instantiate;
-
- static WebSendFile fromJson(Map<String, dynamic> map) {
- return ensureInitialized().decodeMap<WebSendFile>(map);
- }
-
- static WebSendFile deserialize(String json) {
- return ensureInitialized().decodeJson<WebSendFile>(json);
- }
-}
-
-mixin WebSendFileMappable {
- String serialize() {
- return WebSendFileMapper.ensureInitialized().encodeJson<WebSendFile>(
- this as WebSendFile,
- );
- }
-
- Map<String, dynamic> toJson() {
- return WebSendFileMapper.ensureInitialized().encodeMap<WebSendFile>(
- this as WebSendFile,
- );
- }
-
- WebSendFileCopyWith<WebSendFile, WebSendFile, WebSendFile> get copyWith =>
- _WebSendFileCopyWithImpl<WebSendFile, WebSendFile>(
- this as WebSendFile,
- $identity,
- $identity,
- );
- @override
- String toString() {
- return WebSendFileMapper.ensureInitialized().stringifyValue(
- this as WebSendFile,
- );
- }
-
- @override
- bool operator ==(Object other) {
- return WebSendFileMapper.ensureInitialized().equalsValue(
- this as WebSendFile,
- other,
- );
- }
-
- @override
- int get hashCode {
- return WebSendFileMapper.ensureInitialized().hashValue(this as WebSendFile);
- }
-}
-
-extension WebSendFileValueCopy<$R, $Out>
- on ObjectCopyWith<$R, WebSendFile, $Out> {
- WebSendFileCopyWith<$R, WebSendFile, $Out> get $asWebSendFile =>
- $base.as((v, t, t2) => _WebSendFileCopyWithImpl<$R, $Out>(v, t, t2));
-}
-
-abstract class WebSendFileCopyWith<$R, $In extends WebSendFile, $Out>
- implements ClassCopyWith<$R, $In, $Out> {
- ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>>? get bytes;
- $R call({FileDto? file, AssetEntity? asset, String? path, List<int>? bytes});
- WebSendFileCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
-}
-
-class _WebSendFileCopyWithImpl<$R, $Out>
- extends ClassCopyWithBase<$R, WebSendFile, $Out>
- implements WebSendFileCopyWith<$R, WebSendFile, $Out> {
- _WebSendFileCopyWithImpl(super.value, super.then, super.then2);
-
- @override
- late final ClassMapperBase<WebSendFile> $mapper =
- WebSendFileMapper.ensureInitialized();
- @override
- ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>>? get bytes =>
- $value.bytes != null
- ? ListCopyWith(
- $value.bytes!,
- (v, t) => ObjectCopyWith(v, $identity, t),
- (v) => call(bytes: v),
- )
- : null;
- @override
- $R call({
- FileDto? file,
- Object? asset = $none,
- Object? path = $none,
- Object? bytes = $none,
- }) => $apply(
- FieldCopyWithData({
- if (file != null) #file: file,
- if (asset != $none) #asset: asset,
- if (path != $none) #path: path,
- if (bytes != $none) #bytes: bytes,
- }),
- );
- @override
- WebSendFile $make(CopyWithData data) => WebSendFile(
- file: data.get(#file, or: $value.file),
- asset: data.get(#asset, or: $value.asset),
- path: data.get(#path, or: $value.path),
- bytes: data.get(#bytes, or: $value.bytes),
- );
-
- @override
- WebSendFileCopyWith<$R2, WebSendFile, $Out2> $chain<$R2, $Out2>(
- Then<$Out2, $R2> t,
- ) => _WebSendFileCopyWithImpl<$R2, $Out2>($value, $cast, t);
-}
-
diff --git a/app/lib/model/state/send/web/web_send_session.mapper.dart b/app/lib/model/state/send/web/web_send_session.mapper.dart
deleted file mode 100644
index 70c5ed0d..00000000
--- a/app/lib/model/state/send/web/web_send_session.mapper.dart
+++ /dev/null
@@ -1,159 +0,0 @@
-// coverage:ignore-file
-// GENERATED CODE - DO NOT MODIFY BY HAND
-// dart format off
-// ignore_for_file: type=lint
-// ignore_for_file: invalid_use_of_protected_member
-// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
-// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
-
-part of 'web_send_session.dart';
-
-class WebSendSessionMapper extends ClassMapperBase<WebSendSession> {
- WebSendSessionMapper._();
-
- static WebSendSessionMapper? _instance;
- static WebSendSessionMapper ensureInitialized() {
- if (_instance == null) {
- MapperContainer.globals.use(_instance = WebSendSessionMapper._());
- }
- return _instance!;
- }
-
- @override
- final String id = 'WebSendSession';
-
- static String _$sessionId(WebSendSession v) => v.sessionId;
- static const Field<WebSendSession, String> _f$sessionId = Field(
- 'sessionId',
- _$sessionId,
- );
- static bool _$pending(WebSendSession v) => v.pending;
- static const Field<WebSendSession, bool> _f$pending = Field(
- 'pending',
- _$pending,
- );
- static String _$ip(WebSendSession v) => v.ip;
- static const Field<WebSendSession, String> _f$ip = Field('ip', _$ip);
- static String _$deviceInfo(WebSendSession v) => v.deviceInfo;
- static const Field<WebSendSession, String> _f$deviceInfo = Field(
- 'deviceInfo',
- _$deviceInfo,
- );
-
- @override
- final MappableFields<WebSendSession> fields = const {
- #sessionId: _f$sessionId,
- #pending: _f$pending,
- #ip: _f$ip,
- #deviceInfo: _f$deviceInfo,
- };
-
- static WebSendSession _instantiate(DecodingData data) {
- return WebSendSession(
- sessionId: data.dec(_f$sessionId),
- pending: data.dec(_f$pending),
- ip: data.dec(_f$ip),
- deviceInfo: data.dec(_f$deviceInfo),
- );
- }
-
- @override
- final Function instantiate = _instantiate;
-
- static WebSendSession fromJson(Map<String, dynamic> map) {
- return ensureInitialized().decodeMap<WebSendSession>(map);
- }
-
- static WebSendSession deserialize(String json) {
- return ensureInitialized().decodeJson<WebSendSession>(json);
- }
-}
-
-mixin WebSendSessionMappable {
- String serialize() {
- return WebSendSessionMapper.ensureInitialized().encodeJson<WebSendSession>(
- this as WebSendSession,
- );
- }
-
- Map<String, dynamic> toJson() {
- return WebSendSessionMapper.ensureInitialized().encodeMap<WebSendSession>(
- this as WebSendSession,
- );
- }
-
- WebSendSessionCopyWith<WebSendSession, WebSendSession, WebSendSession>
- get copyWith => _WebSendSessionCopyWithImpl<WebSendSession, WebSendSession>(
- this as WebSendSession,
- $identity,
- $identity,
- );
- @override
- String toString() {
- return WebSendSessionMapper.ensureInitialized().stringifyValue(
- this as WebSendSession,
- );
- }
-
- @override
- bool operator ==(Object other) {
- return WebSendSessionMapper.ensureInitialized().equalsValue(
- this as WebSendSession,
- other,
- );
- }
-
- @override
- int get hashCode {
- return WebSendSessionMapper.ensureInitialized().hashValue(
- this as WebSendSession,
- );
- }
-}
-
-extension WebSendSessionValueCopy<$R, $Out>
- on ObjectCopyWith<$R, WebSendSession, $Out> {
- WebSendSessionCopyWith<$R, WebSendSession, $Out> get $asWebSendSession =>
- $base.as((v, t, t2) => _WebSendSessionCopyWithImpl<$R, $Out>(v, t, t2));
-}
-
-abstract class WebSendSessionCopyWith<$R, $In extends WebSendSession, $Out>
- implements ClassCopyWith<$R, $In, $Out> {
- $R call({String? sessionId, bool? pending, String? ip, String? deviceInfo});
- WebSendSessionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
- Then<$Out2, $R2> t,
- );
-}
-
-class _WebSendSessionCopyWithImpl<$R, $Out>
- extends ClassCopyWithBase<$R, WebSendSession, $Out>
- implements WebSendSessionCopyWith<$R, WebSendSession, $Out> {
- _WebSendSessionCopyWithImpl(super.value, super.then, super.then2);
-
- @override
- late final ClassMapperBase<WebSendSession> $mapper =
- WebSendSessionMapper.ensureInitialized();
- @override
- $R call({String? sessionId, bool? pending, String? ip, String? deviceInfo}) =>
- $apply(
- FieldCopyWithData({
- if (sessionId != null) #sessionId: sessionId,
- if (pending != null) #pending: pending,
- if (ip != null) #ip: ip,
- if (deviceInfo != null) #deviceInfo: deviceInfo,
- }),
- );
- @override
- WebSendSession $make(CopyWithData data) => WebSendSession(
- sessionId: data.get(#sessionId, or: $value.sessionId),
- pending: data.get(#pending, or: $value.pending),
- ip: data.get(#ip, or: $value.ip),
- deviceInfo: data.get(#deviceInfo, or: $value.deviceInfo),
- );
-
- @override
- WebSendSessionCopyWith<$R2, WebSendSession, $Out2> $chain<$R2, $Out2>(
- Then<$Out2, $R2> t,
- ) => _WebSendSessionCopyWithImpl<$R2, $Out2>($value, $cast, t);
-}
-
diff --git a/app/lib/model/state/send/web/web_send_state.dart b/app/lib/model/state/send/web/web_send_state.dart
deleted file mode 100644
index 37fad3cb..00000000
--- a/app/lib/model/state/send/web/web_send_state.dart
+++ /dev/null
@@ -1,23 +0,0 @@
-import 'package:dart_mappable/dart_mappable.dart';
-import 'package:localsend_app/model/state/send/web/web_send_file.dart';
-import 'package:localsend_app/model/state/send/web/web_send_session.dart';
-
-part 'web_send_state.mapper.dart';
-
-@MappableClass()
-class WebSendState with WebSendStateMappable {
- final Map<String, WebSendSession> sessions; // session id -> session data, also includes incoming requests
- final Map<String, WebSendFile> files; // file id as key
- final bool autoAccept; // automatically accept incoming requests
-
- const WebSendState({
- required this.sessions,
- required this.files,
- required this.autoAccept,
- });
-
- @override
- String toString() {
- return 'WebSendState(sessions: $sessions, files: <${files.keys}>, autoAccept: $autoAccept)';
- }
-}
diff --git a/app/lib/model/state/send/web/web_send_state.mapper.dart b/app/lib/model/state/send/web/web_send_state.mapper.dart
deleted file mode 100644
index c2eb3e7d..00000000
--- a/app/lib/model/state/send/web/web_send_state.mapper.dart
+++ /dev/null
@@ -1,196 +0,0 @@
-// coverage:ignore-file
-// GENERATED CODE - DO NOT MODIFY BY HAND
-// dart format off
-// ignore_for_file: type=lint
-// ignore_for_file: invalid_use_of_protected_member
-// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
-// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
-
-part of 'web_send_state.dart';
-
-class WebSendStateMapper extends ClassMapperBase<WebSendState> {
- WebSendStateMapper._();
-
- static WebSendStateMapper? _instance;
- static WebSendStateMapper ensureInitialized() {
- if (_instance == null) {
- MapperContainer.globals.use(_instance = WebSendStateMapper._());
- WebSendSessionMapper.ensureInitialized();
- WebSendFileMapper.ensureInitialized();
- }
- return _instance!;
- }
-
- @override
- final String id = 'WebSendState';
-
- static Map<String, WebSendSession> _$sessions(WebSendState v) => v.sessions;
- static const Field<WebSendState, Map<String, WebSendSession>> _f$sessions =
- Field('sessions', _$sessions);
- static Map<String, WebSendFile> _$files(WebSendState v) => v.files;
- static const Field<WebSendState, Map<String, WebSendFile>> _f$files = Field(
- 'files',
- _$files,
- );
- static bool _$autoAccept(WebSendState v) => v.autoAccept;
- static const Field<WebSendState, bool> _f$autoAccept = Field(
- 'autoAccept',
- _$autoAccept,
- );
-
- @override
- final MappableFields<WebSendState> fields = const {
- #sessions: _f$sessions,
- #files: _f$files,
- #autoAccept: _f$autoAccept,
- };
-
- static WebSendState _instantiate(DecodingData data) {
- return WebSendState(
- sessions: data.dec(_f$sessions),
- files: data.dec(_f$files),
- autoAccept: data.dec(_f$autoAccept),
- );
- }
-
- @override
- final Function instantiate = _instantiate;
-
- static WebSendState fromJson(Map<String, dynamic> map) {
- return ensureInitialized().decodeMap<WebSendState>(map);
- }
-
- static WebSendState deserialize(String json) {
- return ensureInitialized().decodeJson<WebSendState>(json);
- }
-}
-
-mixin WebSendStateMappable {
- String serialize() {
- return WebSendStateMapper.ensureInitialized().encodeJson<WebSendState>(
- this as WebSendState,
- );
- }
-
- Map<String, dynamic> toJson() {
- return WebSendStateMapper.ensureInitialized().encodeMap<WebSendState>(
- this as WebSendState,
- );
- }
-
- WebSendStateCopyWith<WebSendState, WebSendState, WebSendState> get copyWith =>
- _WebSendStateCopyWithImpl<WebSendState, WebSendState>(
- this as WebSendState,
- $identity,
- $identity,
- );
- @override
- String toString() {
- return WebSendStateMapper.ensureInitialized().stringifyValue(
- this as WebSendState,
- );
- }
-
- @override
- bool operator ==(Object other) {
- return WebSendStateMapper.ensureInitialized().equalsValue(
- this as WebSendState,
- other,
- );
- }
-
- @override
- int get hashCode {
- return WebSendStateMapper.ensureInitialized().hashValue(
- this as WebSendState,
- );
- }
-}
-
-extension WebSendStateValueCopy<$R, $Out>
- on ObjectCopyWith<$R, WebSendState, $Out> {
- WebSendStateCopyWith<$R, WebSendState, $Out> get $asWebSendState =>
- $base.as((v, t, t2) => _WebSendStateCopyWithImpl<$R, $Out>(v, t, t2));
-}
-
-abstract class WebSendStateCopyWith<$R, $In extends WebSendState, $Out>
- implements ClassCopyWith<$R, $In, $Out> {
- MapCopyWith<
- $R,
- String,
- WebSendSession,
- WebSendSessionCopyWith<$R, WebSendSession, WebSendSession>
- >
- get sessions;
- MapCopyWith<
- $R,
- String,
- WebSendFile,
- WebSendFileCopyWith<$R, WebSendFile, WebSendFile>
- >
- get files;
- $R call({
- Map<String, WebSendSession>? sessions,
- Map<String, WebSendFile>? files,
- bool? autoAccept,
- });
- WebSendStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
-}
-
-class _WebSendStateCopyWithImpl<$R, $Out>
- extends ClassCopyWithBase<$R, WebSendState, $Out>
- implements WebSendStateCopyWith<$R, WebSendState, $Out> {
- _WebSendStateCopyWithImpl(super.value, super.then, super.then2);
-
- @override
- late final ClassMapperBase<WebSendState> $mapper =
- WebSendStateMapper.ensureInitialized();
- @override
- MapCopyWith<
- $R,
- String,
- WebSendSession,
- WebSendSessionCopyWith<$R, WebSendSession, WebSendSession>
- >
- get sessions => MapCopyWith(
- $value.sessions,
- (v, t) => v.copyWith.$chain(t),
- (v) => call(sessions: v),
- );
- @override
- MapCopyWith<
- $R,
- String,
- WebSendFile,
- WebSendFileCopyWith<$R, WebSendFile, WebSendFile>
- >
- get files => MapCopyWith(
- $value.files,
- (v, t) => v.copyWith.$chain(t),
- (v) => call(files: v),
- );
- @override
- $R call({
- Map<String, WebSendSession>? sessions,
- Map<String, WebSendFile>? files,
- bool? autoAccept,
- }) => $apply(
- FieldCopyWithData({
- if (sessions != null) #sessions: sessions,
- if (files != null) #files: files,
- if (autoAccept != null) #autoAccept: autoAccept,
- }),
- );
- @override
- WebSendState $make(CopyWithData data) => WebSendState(
- sessions: data.get(#sessions, or: $value.sessions),
- files: data.get(#files, or: $value.files),
- autoAccept: data.get(#autoAccept, or: $value.autoAccept),
- );
-
- @override
- WebSendStateCopyWith<$R2, WebSendState, $Out2> $chain<$R2, $Out2>(
- Then<$Out2, $R2> t,
- ) => _WebSendStateCopyWithImpl<$R2, $Out2>($value, $cast, t);
-}
-
diff --git a/app/lib/model/state/server/server_state.dart b/app/lib/model/state/server/server_state.dart
index 567ee578..48a77b0d 100644
--- a/app/lib/model/state/server/server_state.dart
+++ b/app/lib/model/state/server/server_state.dart
@@ -1,6 +1,7 @@
import 'package:dart_mappable/dart_mappable.dart';
-import 'package:localsend_app/model/state/send/web/web_send_state.dart';
+import 'package:localsend_app/model/state/send/web/web_download_state.dart';
import 'package:localsend_app/model/state/server/receive_session_state.dart';
+import 'package:localsend_app/model/state/server/web_share_state.dart';
part 'server_state.mapper.dart';
@@ -10,27 +11,40 @@ class ServerState with ServerStateMappable {
final int port;
final bool https;
final ReceiveSessionState? session;
- final WebSendState? webSendState;
- /// Whether the upload page is served so web browsers can upload files.
- final bool webUpload;
-
- /// Optional session-scoped PIN of the active web share mode (download or upload page).
- /// The PIN is enforced by the Rust server; changing it requires a server restart.
- final String? webPin;
+ /// Which web share is active (download or upload page). `null` when disabled.
+ final WebShareState? web;
const ServerState({
required this.alias,
required this.port,
required this.https,
required this.session,
- required this.webSendState,
- required this.webUpload,
- required this.webPin,
+ required this.web,
});
+ /// The web download state while the download page is served.
+ WebDownloadState? get webDownloadState => switch (web) {
+ WebShareDownload(:final state) => state,
+ _ => null,
+ };
+
+ /// Whether the upload page is served so web browsers can upload files.
+ bool get webUpload => web is WebShareUpload;
+
+ /// Returns a copy with the [WebDownloadState] of the active download share updated.
+ /// Returns this state unchanged when the download page is not active.
+ ServerState updateWebDownloadState(WebDownloadState Function(WebDownloadState state) update) {
+ return switch (web) {
+ WebShareDownload(:final state, :final pin) => copyWith(
+ web: WebShareDownload(state: update(state), pin: pin),
+ ),
+ _ => this,
+ };
+ }
+
@override
String toString() {
- return 'ServerState(alias: $alias, port: $port, https: $https, session: $session, webSendState: $webSendState, webUpload: $webUpload, webPin: $webPin)';
+ return 'ServerState(alias: $alias, port: $port, https: $https, session: $session, web: $web)';
}
}
diff --git a/app/lib/model/state/server/server_state.mapper.dart b/app/lib/model/state/server/server_state.mapper.dart
index 216eb7d4..9ae795e7 100644
--- a/app/lib/model/state/server/server_state.mapper.dart
+++ b/app/lib/model/state/server/server_state.mapper.dart
@@ -16,7 +16,7 @@ class ServerStateMapper extends ClassMapperBase<ServerState> {
if (_instance == null) {
MapperContainer.globals.use(_instance = ServerStateMapper._());
ReceiveSessionStateMapper.ensureInitialized();
- WebSendStateMapper.ensureInitialized();
+ WebShareStateMapper.ensureInitialized();
}
return _instance!;
}
@@ -35,18 +35,8 @@ class ServerStateMapper extends ClassMapperBase<ServerState> {
'session',
_$session,
);
- static WebSendState? _$webSendState(ServerState v) => v.webSendState;
- static const Field<ServerState, WebSendState> _f$webSendState = Field(
- 'webSendState',
- _$webSendState,
- );
- static bool _$webUpload(ServerState v) => v.webUpload;
- static const Field<ServerState, bool> _f$webUpload = Field(
- 'webUpload',
- _$webUpload,
- );
- static String? _$webPin(ServerState v) => v.webPin;
- static const Field<ServerState, String> _f$webPin = Field('webPin', _$webPin);
+ static WebShareState? _$web(ServerState v) => v.web;
+ static const Field<ServerState, WebShareState> _f$web = Field('web', _$web);
@override
final MappableFields<ServerState> fields = const {
@@ -54,9 +44,7 @@ class ServerStateMapper extends ClassMapperBase<ServerState> {
#port: _f$port,
#https: _f$https,
#session: _f$session,
- #webSendState: _f$webSendState,
- #webUpload: _f$webUpload,
- #webPin: _f$webPin,
+ #web: _f$web,
};
static ServerState _instantiate(DecodingData data) {
@@ -65,9 +53,7 @@ class ServerStateMapper extends ClassMapperBase<ServerState> {
port: data.dec(_f$port),
https: data.dec(_f$https),
session: data.dec(_f$session),
- webSendState: data.dec(_f$webSendState),
- webUpload: data.dec(_f$webUpload),
- webPin: data.dec(_f$webPin),
+ web: data.dec(_f$web),
);
}
@@ -133,15 +119,13 @@ abstract class ServerStateCopyWith<$R, $In extends ServerState, $Out>
implements ClassCopyWith<$R, $In, $Out> {
ReceiveSessionStateCopyWith<$R, ReceiveSessionState, ReceiveSessionState>?
get session;
- WebSendStateCopyWith<$R, WebSendState, WebSendState>? get webSendState;
+ WebShareStateCopyWith<$R, WebShareState, WebShareState>? get web;
$R call({
String? alias,
int? port,
bool? https,
ReceiveSessionState? session,
- WebSendState? webSendState,
- bool? webUpload,
- String? webPin,
+ WebShareState? web,
});
ServerStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}
@@ -158,26 +142,22 @@ class _ServerStateCopyWithImpl<$R, $Out>
ReceiveSessionStateCopyWith<$R, ReceiveSessionState, ReceiveSessionState>?
get session => $value.session?.copyWith.$chain((v) => call(session: v));
@override
- WebSendStateCopyWith<$R, WebSendState, WebSendState>? get webSendState =>
- $value.webSendState?.copyWith.$chain((v) => call(webSendState: v));
+ WebShareStateCopyWith<$R, WebShareState, WebShareState>? get web =>
+ $value.web?.copyWith.$chain((v) => call(web: v));
@override
$R call({
String? alias,
int? port,
bool? https,
Object? session = $none,
- Object? webSendState = $none,
- bool? webUpload,
- Object? webPin = $none,
+ Object? web = $none,
}) => $apply(
FieldCopyWithData({
if (alias != null) #alias: alias,
if (port != null) #port: port,
if (https != null) #https: https,
if (session != $none) #session: session,
- if (webSendState != $none) #webSendState: webSendState,
- if (webUpload != null) #webUpload: webUpload,
- if (webPin != $none) #webPin: webPin,
+ if (web != $none) #web: web,
}),
);
@override
@@ -186,9 +166,7 @@ class _ServerStateCopyWithImpl<$R, $Out>
port: data.get(#port, or: $value.port),
https: data.get(#https, or: $value.https),
session: data.get(#session, or: $value.session),
- webSendState: data.get(#webSendState, or: $value.webSendState),
- webUpload: data.get(#webUpload, or: $value.webUpload),
- webPin: data.get(#webPin, or: $value.webPin),
+ web: data.get(#web, or: $value.web),
);
@override
diff --git a/app/lib/model/state/server/web_share_state.dart b/app/lib/model/state/server/web_share_state.dart
new file mode 100644
index 00000000..bf34066a
--- /dev/null
+++ b/app/lib/model/state/server/web_share_state.dart
@@ -0,0 +1,32 @@
+import 'package:dart_mappable/dart_mappable.dart';
+import 'package:localsend_app/model/state/send/web/web_download_state.dart';
+
+part 'web_share_state.mapper.dart';
+
+/// Which web share is active, i.e. which page the server serves to browsers.
+/// `null` on [ServerState.web] means no web share is active.
+///
+/// The [pin] protects the served page. It is enforced by the Rust server;
+/// changing it requires a server restart.
+@MappableClass()
+sealed class WebShareState with WebShareStateMappable {
+ final String? pin;
+
+ const WebShareState({required this.pin});
+}
+
+/// Web download: the download page is served, offering the files in [state] for
+/// download by web browsers.
+@MappableClass()
+class WebShareDownload extends WebShareState with WebShareDownloadMappable {
+ final WebDownloadState state;
+
+ const WebShareDownload({required this.state, required super.pin});
+}
+
+/// The upload page is served so web browsers can upload files.
+/// The [pin] replaces the receive pin from settings.
+@MappableClass()
+class WebShareUpload extends WebShareState with WebShareUploadMappable {
+ const WebShareUpload({required super.pin});
+}
diff --git a/app/lib/model/state/server/web_share_state.mapper.dart b/app/lib/model/state/server/web_share_state.mapper.dart
new file mode 100644
index 00000000..0ef06885
--- /dev/null
+++ b/app/lib/model/state/server/web_share_state.mapper.dart
@@ -0,0 +1,310 @@
+// coverage:ignore-file
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// dart format off
+// ignore_for_file: type=lint
+// ignore_for_file: invalid_use_of_protected_member
+// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
+// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
+
+part of 'web_share_state.dart';
+
+class WebShareStateMapper extends ClassMapperBase<WebShareState> {
+ WebShareStateMapper._();
+
+ static WebShareStateMapper? _instance;
+ static WebShareStateMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebShareStateMapper._());
+ WebShareDownloadMapper.ensureInitialized();
+ WebShareUploadMapper.ensureInitialized();
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebShareState';
+
+ static String? _$pin(WebShareState v) => v.pin;
+ static const Field<WebShareState, String> _f$pin = Field('pin', _$pin);
+
+ @override
+ final MappableFields<WebShareState> fields = const {#pin: _f$pin};
+
+ static WebShareState _instantiate(DecodingData data) {
+ throw MapperException.missingConstructor('WebShareState');
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebShareState fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebShareState>(map);
+ }
+
+ static WebShareState deserialize(String json) {
+ return ensureInitialized().decodeJson<WebShareState>(json);
+ }
+}
+
+mixin WebShareStateMappable {
+ String serialize();
+ Map<String, dynamic> toJson();
+ WebShareStateCopyWith<WebShareState, WebShareState, WebShareState>
+ get copyWith;
+}
+
+abstract class WebShareStateCopyWith<$R, $In extends WebShareState, $Out>
+ implements ClassCopyWith<$R, $In, $Out> {
+ $R call({String? pin});
+ WebShareStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
+}
+
+class WebShareDownloadMapper extends ClassMapperBase<WebShareDownload> {
+ WebShareDownloadMapper._();
+
+ static WebShareDownloadMapper? _instance;
+ static WebShareDownloadMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebShareDownloadMapper._());
+ WebShareStateMapper.ensureInitialized();
+ WebDownloadStateMapper.ensureInitialized();
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebShareDownload';
+
+ static WebDownloadState _$state(WebShareDownload v) => v.state;
+ static const Field<WebShareDownload, WebDownloadState> _f$state = Field(
+ 'state',
+ _$state,
+ );
+ static String? _$pin(WebShareDownload v) => v.pin;
+ static const Field<WebShareDownload, String> _f$pin = Field('pin', _$pin);
+
+ @override
+ final MappableFields<WebShareDownload> fields = const {
+ #state: _f$state,
+ #pin: _f$pin,
+ };
+
+ static WebShareDownload _instantiate(DecodingData data) {
+ return WebShareDownload(state: data.dec(_f$state), pin: data.dec(_f$pin));
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebShareDownload fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebShareDownload>(map);
+ }
+
+ static WebShareDownload deserialize(String json) {
+ return ensureInitialized().decodeJson<WebShareDownload>(json);
+ }
+}
+
+mixin WebShareDownloadMappable {
+ String serialize() {
+ return WebShareDownloadMapper.ensureInitialized()
+ .encodeJson<WebShareDownload>(this as WebShareDownload);
+ }
+
+ Map<String, dynamic> toJson() {
+ return WebShareDownloadMapper.ensureInitialized()
+ .encodeMap<WebShareDownload>(this as WebShareDownload);
+ }
+
+ WebShareDownloadCopyWith<WebShareDownload, WebShareDownload, WebShareDownload>
+ get copyWith =>
+ _WebShareDownloadCopyWithImpl<WebShareDownload, WebShareDownload>(
+ this as WebShareDownload,
+ $identity,
+ $identity,
+ );
+ @override
+ String toString() {
+ return WebShareDownloadMapper.ensureInitialized().stringifyValue(
+ this as WebShareDownload,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return WebShareDownloadMapper.ensureInitialized().equalsValue(
+ this as WebShareDownload,
+ other,
+ );
+ }
+
+ @override
+ int get hashCode {
+ return WebShareDownloadMapper.ensureInitialized().hashValue(
+ this as WebShareDownload,
+ );
+ }
+}
+
+extension WebShareDownloadValueCopy<$R, $Out>
+ on ObjectCopyWith<$R, WebShareDownload, $Out> {
+ WebShareDownloadCopyWith<$R, WebShareDownload, $Out>
+ get $asWebShareDownload =>
+ $base.as((v, t, t2) => _WebShareDownloadCopyWithImpl<$R, $Out>(v, t, t2));
+}
+
+abstract class WebShareDownloadCopyWith<$R, $In extends WebShareDownload, $Out>
+ implements WebShareStateCopyWith<$R, $In, $Out> {
+ WebDownloadStateCopyWith<$R, WebDownloadState, WebDownloadState> get state;
+ @override
+ $R call({WebDownloadState? state, String? pin});
+ WebShareDownloadCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ );
+}
+
+class _WebShareDownloadCopyWithImpl<$R, $Out>
+ extends ClassCopyWithBase<$R, WebShareDownload, $Out>
+ implements WebShareDownloadCopyWith<$R, WebShareDownload, $Out> {
+ _WebShareDownloadCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<WebShareDownload> $mapper =
+ WebShareDownloadMapper.ensureInitialized();
+ @override
+ WebDownloadStateCopyWith<$R, WebDownloadState, WebDownloadState> get state =>
+ $value.state.copyWith.$chain((v) => call(state: v));
+ @override
+ $R call({WebDownloadState? state, Object? pin = $none}) => $apply(
+ FieldCopyWithData({
+ if (state != null) #state: state,
+ if (pin != $none) #pin: pin,
+ }),
+ );
+ @override
+ WebShareDownload $make(CopyWithData data) => WebShareDownload(
+ state: data.get(#state, or: $value.state),
+ pin: data.get(#pin, or: $value.pin),
+ );
+
+ @override
+ WebShareDownloadCopyWith<$R2, WebShareDownload, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ ) => _WebShareDownloadCopyWithImpl<$R2, $Out2>($value, $cast, t);
+}
+
+class WebShareUploadMapper extends ClassMapperBase<WebShareUpload> {
+ WebShareUploadMapper._();
+
+ static WebShareUploadMapper? _instance;
+ static WebShareUploadMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = WebShareUploadMapper._());
+ WebShareStateMapper.ensureInitialized();
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'WebShareUpload';
+
+ static String? _$pin(WebShareUpload v) => v.pin;
+ static const Field<WebShareUpload, String> _f$pin = Field('pin', _$pin);
+
+ @override
+ final MappableFields<WebShareUpload> fields = const {#pin: _f$pin};
+
+ static WebShareUpload _instantiate(DecodingData data) {
+ return WebShareUpload(pin: data.dec(_f$pin));
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static WebShareUpload fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<WebShareUpload>(map);
+ }
+
+ static WebShareUpload deserialize(String json) {
+ return ensureInitialized().decodeJson<WebShareUpload>(json);
+ }
+}
+
+mixin WebShareUploadMappable {
+ String serialize() {
+ return WebShareUploadMapper.ensureInitialized().encodeJson<WebShareUpload>(
+ this as WebShareUpload,
+ );
+ }
+
+ Map<String, dynamic> toJson() {
+ return WebShareUploadMapper.ensureInitialized().encodeMap<WebShareUpload>(
+ this as WebShareUpload,
+ );
+ }
+
+ WebShareUploadCopyWith<WebShareUpload, WebShareUpload, WebShareUpload>
+ get copyWith => _WebShareUploadCopyWithImpl<WebShareUpload, WebShareUpload>(
+ this as WebShareUpload,
+ $identity,
+ $identity,
+ );
+ @override
+ String toString() {
+ return WebShareUploadMapper.ensureInitialized().stringifyValue(
+ this as WebShareUpload,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return WebShareUploadMapper.ensureInitialized().equalsValue(
+ this as WebShareUpload,
+ other,
+ );
+ }
+
+ @override
+ int get hashCode {
+ return WebShareUploadMapper.ensureInitialized().hashValue(
+ this as WebShareUpload,
+ );
+ }
+}
+
+extension WebShareUploadValueCopy<$R, $Out>
+ on ObjectCopyWith<$R, WebShareUpload, $Out> {
+ WebShareUploadCopyWith<$R, WebShareUpload, $Out> get $asWebShareUpload =>
+ $base.as((v, t, t2) => _WebShareUploadCopyWithImpl<$R, $Out>(v, t, t2));
+}
+
+abstract class WebShareUploadCopyWith<$R, $In extends WebShareUpload, $Out>
+ implements WebShareStateCopyWith<$R, $In, $Out> {
+ @override
+ $R call({String? pin});
+ WebShareUploadCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ );
+}
+
+class _WebShareUploadCopyWithImpl<$R, $Out>
+ extends ClassCopyWithBase<$R, WebShareUpload, $Out>
+ implements WebShareUploadCopyWith<$R, WebShareUpload, $Out> {
+ _WebShareUploadCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<WebShareUpload> $mapper =
+ WebShareUploadMapper.ensureInitialized();
+ @override
+ $R call({Object? pin = $none}) =>
+ $apply(FieldCopyWithData({if (pin != $none) #pin: pin}));
+ @override
+ WebShareUpload $make(CopyWithData data) =>
+ WebShareUpload(pin: data.get(#pin, or: $value.pin));
+
+ @override
+ WebShareUploadCopyWith<$R2, WebShareUpload, $Out2> $chain<$R2, $Out2>(
+ Then<$Out2, $R2> t,
+ ) => _WebShareUploadCopyWithImpl<$R2, $Out2>($value, $cast, t);
+}
+
diff --git a/app/lib/pages/web_share_page.dart b/app/lib/pages/web_share_page.dart
index 2a02ced0..ace7e5fd 100644
--- a/app/lib/pages/web_share_page.dart
+++ b/app/lib/pages/web_share_page.dart
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:localsend_app/config/theme.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/cross_file.dart';
+import 'package:localsend_app/model/state/server/web_share_state.dart';
import 'package:localsend_app/provider/local_ip_provider.dart';
import 'package:localsend_app/provider/network/server/server_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
@@ -65,20 +66,19 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
// The pin of a previous web share session is kept;
// receive mode initially uses the receive pin from settings.
- final previousState = ref.read(serverProvider);
- final wasWebActive = previousState?.webSendState != null || previousState?.webUpload == true;
- final webPin = wasWebActive ? previousState?.webPin : (files == null ? settings.receivePin : null);
+ final previousWeb = ref.read(serverProvider)?.web;
+ final webPin = previousWeb != null ? previousWeb.pin : (files == null ? settings.receivePin : null);
if (files != null) {
- // The auto accept setting of a previous web send state is kept.
+ // The auto accept setting of a previous web download state is kept.
await ref
.notifier(serverProvider)
- .restartServerWithWebSend(
+ .restartServerWithWebDownload(
alias: settings.alias,
port: settings.port,
https: _encrypted,
files: files,
- webPin: webPin,
+ pin: webPin,
);
} else {
await ref
@@ -87,8 +87,7 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
alias: settings.alias,
port: settings.port,
https: _encrypted,
- webUpload: true,
- webPin: webPin,
+ web: WebShareUpload(pin: webPin),
);
}
setState(() {
@@ -171,14 +170,14 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
}
final serverState = context.watch(serverProvider);
- final webSendState = serverState?.webSendState;
- if (serverState == null || (_sendMode && webSendState == null)) {
+ final webDownloadState = serverState?.webDownloadState;
+ if (serverState == null || (_sendMode && webDownloadState == null)) {
// the server is restarting (e.g. because the pin changed)
return const Center(child: CircularProgressIndicator());
}
final networkState = context.watch(localIpProvider);
final settings = context.watch(settingsProvider);
- final pin = serverState.webPin;
+ final pin = serverState.web?.pin;
return ResponsiveListView(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
@@ -226,7 +225,7 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
builder: (_) => QrDialog(
data: urlWithPin,
label: url,
- listenIncomingWebSendRequests: _sendMode,
+ listenIncomingWebDownloadRequests: _sendMode,
pin: pin,
),
);
@@ -242,7 +241,7 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
context: context,
builder: (_) => ZoomDialog(
label: url,
- listenIncomingWebSendRequests: _sendMode,
+ listenIncomingWebDownloadRequests: _sendMode,
pin: pin,
),
);
@@ -261,15 +260,15 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
),
),
const SizedBox(height: 20),
- if (webSendState != null) ...[
+ if (webDownloadState != null) ...[
Text(t.webSharePage.requests, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 10),
- if (webSendState.sessions.isEmpty)
+ if (webDownloadState.sessions.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Text(t.webSharePage.noRequests),
),
- ...webSendState.sessions.entries.map((entry) {
+ ...webDownloadState.sessions.entries.map((entry) {
final session = entry.value;
return Padding(
padding: const EdgeInsets.only(bottom: 10),
@@ -296,7 +295,7 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
if (session.pending) ...[
TextButton(
onPressed: () {
- ref.notifier(serverProvider).declineWebSendRequest(session.sessionId);
+ ref.notifier(serverProvider).declineWebDownloadRequest(session.sessionId);
},
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
@@ -306,7 +305,7 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
),
TextButton(
onPressed: () {
- ref.notifier(serverProvider).acceptWebSendRequest(session.sessionId);
+ ref.notifier(serverProvider).acceptWebDownloadRequest(session.sessionId);
},
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
@@ -355,10 +354,10 @@ class _WebSharePageState extends State<WebSharePage> with Refena {
Text(t.webSharePage.autoAccept, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(width: 10),
Checkbox(
- value: webSendState != null ? webSendState.autoAccept : settings.receiveViaLinkAutoAccept,
+ value: webDownloadState != null ? webDownloadState.autoAccept : settings.receiveViaLinkAutoAccept,
onChanged: (value) async {
- if (webSendState != null) {
- ref.notifier(serverProvider).setWebSendAutoAccept(value == true);
+ if (webDownloadState != null) {
+ ref.notifier(serverProvider).setWebDownloadAutoAccept(value == true);
} else {
await ref.notifier(settingsProvider).setReceiveViaLinkAutoAccept(value == true);
}
diff --git a/app/lib/provider/device_info_provider.dart b/app/lib/provider/device_info_provider.dart
index 3a2e9941..cbecfa6d 100644
--- a/app/lib/provider/device_info_provider.dart
+++ b/app/lib/provider/device_info_provider.dart
@@ -44,7 +44,7 @@ final deviceFullInfoProvider = ViewProvider((ref) {
fingerprint: securityContext.certificateHash,
deviceModel: rawInfo.deviceModel,
deviceType: rawInfo.deviceType,
- download: serverState?.webSendState != null,
+ download: serverState?.webDownloadState != null,
channels: const [],
);
});
diff --git a/app/lib/provider/network/server/controller/send_controller.dart b/app/lib/provider/network/server/controller/send_controller.dart
index 6f462c11..62ee9a8c 100644
--- a/app/lib/provider/network/server/controller/send_controller.dart
+++ b/app/lib/provider/network/server/controller/send_controller.dart
@@ -2,9 +2,9 @@ import 'dart:convert';
import 'dart:io';
import 'package:localsend_app/model/cross_file.dart';
-import 'package:localsend_app/model/state/send/web/web_send_file.dart';
-import 'package:localsend_app/model/state/send/web/web_send_session.dart';
-import 'package:localsend_app/model/state/send/web/web_send_state.dart';
+import 'package:localsend_app/model/state/send/web/web_download_file.dart';
+import 'package:localsend_app/model/state/send/web/web_download_session.dart';
+import 'package:localsend_app/model/state/send/web/web_download_state.dart';
import 'package:localsend_app/provider/network/server/server_utils.dart';
import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/util/native/directories.dart';
@@ -19,9 +19,9 @@ import 'package:uuid/uuid.dart';
const _uuid = Uuid();
-final _logger = Logger('WebSendController');
+final _logger = Logger('WebDownloadController');
-/// Handles all server events for web send (sending files to web browsers).
+/// Handles all server events for web download (sending files to web browsers).
/// The web page and the downloads themselves are served by the Rust server
/// which emits the events handled here.
class SendController {
@@ -29,13 +29,13 @@ class SendController {
SendController(this.server);
- /// Builds the [WebSendState] for the given [files].
+ /// Builds the [WebDownloadState] for the given [files].
/// Files that only exist in memory (e.g. text messages) are materialized
/// to the cache directory so the Rust server can stream them.
- Future<WebSendState> buildWebSendState({required List<CrossFile> files}) async {
- final currentWebSendState = server.getStateOrNull()?.webSendState;
+ Future<WebDownloadState> buildWebDownloadState({required List<CrossFile> files}) async {
+ final currentWebDownloadState = server.getStateOrNull()?.webDownloadState;
- return WebSendState(
+ return WebDownloadState(
sessions: {},
files: Map.fromEntries(
await Future.wait(
@@ -46,14 +46,14 @@ class SendController {
if (path == null && file.bytes != null) {
// The Rust server streams file content from disk, so in-memory
// bytes (text messages, clipboard content) are written to a temp file.
- final tempPath = p.join(await getCacheDirectory(), 'web-send-$id');
+ final tempPath = p.join(await getCacheDirectory(), 'web-download-$id');
await File(tempPath).writeAsBytes(file.bytes!);
path = tempPath;
}
return MapEntry(
id,
- WebSendFile(
+ WebDownloadFile(
file: FileDto(
id: id,
fileName: file.name,
@@ -78,7 +78,7 @@ class SendController {
}),
),
),
- autoAccept: currentWebSendState?.autoAccept ?? server.ref.read(settingsProvider).shareViaLinkAutoAccept,
+ autoAccept: currentWebDownloadState?.autoAccept ?? server.ref.read(settingsProvider).shareViaLinkAutoAccept,
);
}
@@ -86,19 +86,19 @@ class SendController {
/// The Rust server already checked the PIN and handles repeated visits of
/// accepted sessions itself.
void onPrepareDownload(HttpServerWebPrepareDownloadEvent event) {
- final webSendState = server.getStateOrNull()?.webSendState;
- if (webSendState == null) {
- // should not happen: web send events are only emitted when web send was configured
+ final webDownloadState = server.getStateOrNull()?.webDownloadState;
+ if (webDownloadState == null) {
+ // should not happen: web download events are only emitted when web download was configured
server.ref.redux(parentIsolateProvider).dispatch(IsolateHttpServerPrepareDownloadDecisionAction(sessionId: event.sessionId, accept: false));
return;
}
server.setState(
- (oldState) => oldState!.copyWith(
- webSendState: oldState.webSendState!.copyWith(
+ (oldState) => oldState!.updateWebDownloadState(
+ (webDownload) => webDownload.copyWith(
sessions: {
- ...oldState.webSendState!.sessions,
- event.sessionId: WebSendSession(
+ ...webDownload.sessions,
+ event.sessionId: WebDownloadSession(
sessionId: event.sessionId,
pending: true,
ip: event.ip,
@@ -109,7 +109,7 @@ class SendController {
),
);
- if (webSendState.autoAccept) {
+ if (webDownloadState.autoAccept) {
acceptRequest(event.sessionId);
}
}
@@ -121,10 +121,10 @@ class SendController {
final String? filePath;
final int? fileDescriptor;
try {
- final path = server.getStateOrNull()?.webSendState?.files[event.fileId]?.path;
+ final path = server.getStateOrNull()?.webDownloadState?.files[event.fileId]?.path;
if (path == null) {
// should not happen: the Rust server only emits events for offered files
- throw StateError('No path for web send file ${event.fileId}');
+ throw StateError('No path for web download file ${event.fileId}');
}
if (path.startsWith('content://')) {
@@ -135,7 +135,7 @@ class SendController {
fileDescriptor = null;
}
} catch (e, st) {
- _logger.severe('Failed to resolve source for web send file ${event.fileId}', e, st);
+ _logger.severe('Failed to resolve source for web download file ${event.fileId}', e, st);
// Unblock the web client's request waiting for the content source.
server.ref.redux(parentIsolateProvider).dispatch(IsolateHttpServerFailFileDownloadAction(sessionId: event.sessionId, fileId: event.fileId));
return;
@@ -154,14 +154,14 @@ class SendController {
}
void acceptRequest(String sessionId) {
- final session = server.getStateOrNull()?.webSendState?.sessions[sessionId];
+ final session = server.getStateOrNull()?.webDownloadState?.sessions[sessionId];
if (session == null || !session.pending) {
return;
}
server.setState(
- (oldState) => oldState!.copyWith(
- webSendState: oldState.webSendState!.updateSession(
+ (oldState) => oldState!.updateWebDownloadState(
+ (webDownload) => webDownload.updateSession(
sessionId: sessionId,
update: (oldSession) => oldSession.copyWith(pending: false),
),
@@ -172,16 +172,16 @@ class SendController {
}
void declineRequest(String sessionId) {
- final session = server.getStateOrNull()?.webSendState?.sessions[sessionId];
+ final session = server.getStateOrNull()?.webDownloadState?.sessions[sessionId];
if (session == null || !session.pending) {
return;
}
server.setState(
- (oldState) => oldState!.copyWith(
- webSendState: oldState.webSendState!.copyWith(
+ (oldState) => oldState!.updateWebDownloadState(
+ (webDownload) => webDownload.copyWith(
sessions: {
- for (final entry in oldState.webSendState!.sessions.entries)
+ for (final entry in webDownload.sessions.entries)
if (entry.key != sessionId) entry.key: entry.value, // remove session
},
),
@@ -212,10 +212,10 @@ String parseDeviceInfoFromUserAgent(String? userAgent) {
}
}
-extension on WebSendState {
- WebSendState updateSession({
+extension on WebDownloadState {
+ WebDownloadState updateSession({
required String sessionId,
- required WebSendSession Function(WebSendSession oldSession) update,
+ required WebDownloadSession Function(WebDownloadSession oldSession) update,
}) {
return copyWith(
sessions: {...sessions}
diff --git a/app/lib/provider/network/server/server_provider.dart b/app/lib/provider/network/server/server_provider.dart
index 70837f09..546bb1b3 100644
--- a/app/lib/provider/network/server/server_provider.dart
+++ b/app/lib/provider/network/server/server_provider.dart
@@ -3,8 +3,8 @@ import 'dart:io';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/cross_file.dart';
-import 'package:localsend_app/model/state/send/web/web_send_state.dart';
import 'package:localsend_app/model/state/server/server_state.dart';
+import 'package:localsend_app/model/state/server/web_share_state.dart';
import 'package:localsend_app/provider/network/server/controller/receive_controller.dart';
import 'package:localsend_app/provider/network/server/controller/send_controller.dart';
import 'package:localsend_app/provider/network/server/server_utils.dart';
@@ -14,7 +14,7 @@ import 'package:localsend_app/util/native/web_pages_loader.dart';
import 'package:localsend_isolates/constants.dart';
import 'package:localsend_isolates/isolate.dart';
import 'package:localsend_isolates/model/dto/multicast_dto.dart';
-import 'package:localsend_isolates/rust/api/server.dart' show WebI18n, WebParams, WebSendParams;
+import 'package:localsend_isolates/rust/api/server.dart' show WebI18n, WebMode, WebParams;
import 'package:localsend_isolates/util/rust.dart';
import 'package:logging/logging.dart';
import 'package:refena_flutter/refena_flutter.dart';
@@ -41,7 +41,7 @@ final serverProvider = NotifierProvider<ServerService, ServerState?>(
next?.port ?? settings.port,
(next?.https ?? settings.https) ? ProtocolType.https : ProtocolType.http,
next != null,
- next?.webSendState != null,
+ next?.webDownloadState != null,
);
if (syncStatePrev == syncStateNext) {
@@ -109,17 +109,14 @@ class ServerService extends Notifier<ServerState?> {
}
/// Starts the server.
- /// Passing a [webSendState] additionally serves the web send (download) API.
- /// Passing [webUpload] serves the upload page so web browsers can upload files.
- /// [webPin] protects the active web share mode: the download page in send mode;
- /// in upload mode, it replaces the receive pin from settings.
+ /// Passing a [web] share additionally serves the download page
+ /// ([WebShareDownload], so web browsers can download the offered files)
+ /// or the upload page ([WebShareUpload], so web browsers can upload files).
Future<ServerState?> startServer({
required String alias,
required int port,
required bool https,
- WebSendState? webSendState,
- bool webUpload = false,
- String? webPin,
+ WebShareState? web,
}) async {
if (state != null) {
_logger.info('Server already running.');
@@ -139,45 +136,48 @@ class ServerService extends Notifier<ServerState?> {
// The server isolate derives its configuration from the sync state,
// so it must be published before the start task.
- _syncServerState(alias: alias, port: port, https: https, serverRunning: true, download: webSendState != null);
+ _syncServerState(alias: alias, port: port, https: https, serverRunning: true, download: web is WebShareDownload);
final settings = ref.read(settingsProvider);
- final webActive = webSendState != null || webUpload;
// Custom pages provided by the user next to the executable, if any.
- final customWebPages = webActive ? await loadCustomWebPages() : null;
+ // A custom error-403.html replaces the built-in 403 page even while no web
+ // share is active; client certificates stay mandatory in that mode.
+ final customWebPages = await loadCustomWebPages();
final events = ref
.redux(parentIsolateProvider)
.dispatchTakeResult(
IsolateHttpServerStartAction(
- pin: webUpload ? webPin : settings.receivePin,
+ pin: switch (web) {
+ WebShareUpload(:final pin) => pin,
+ _ => settings.receivePin,
+ },
verifyChecksums: settings.verifyChecksums,
- web: webActive
- ? WebParams(
- send: webSendState != null
- ? WebSendParams(
- files: {
- for (final entry in webSendState.files.entries) entry.key: entry.value.file.toRust(),
- },
- pin: webPin,
- )
- : null,
- upload: webUpload,
- i18N: WebI18n(
- waiting: t.web.waiting,
- enterPin: t.web.enterPin,
- invalidPin: t.web.invalidPin,
- tooManyAttempts: t.web.tooManyAttempts,
- rejected: t.web.rejected,
- uploadRejected: t.sendPage.rejected,
- busy: t.sendPage.busy,
- files: t.web.files,
- fileName: t.web.fileName,
- size: t.web.size,
- dropHint: t.sendTab.placeItems,
- ),
- pages: customWebPages,
- )
- : null,
+ web: WebParams(
+ mode: switch (web) {
+ WebShareDownload(:final state, :final pin) => WebMode.download(
+ files: {
+ for (final entry in state.files.entries) entry.key: entry.value.file.toRust(),
+ },
+ pin: pin,
+ ),
+ WebShareUpload() => const WebMode.upload(),
+ null => const WebMode.disabled(),
+ },
+ i18N: WebI18n(
+ waiting: t.web.waiting,
+ enterPin: t.web.enterPin,
+ invalidPin: t.web.invalidPin,
+ tooManyAttempts: t.web.tooManyAttempts,
+ rejected: t.web.rejected,
+ uploadRejected: t.sendPage.rejected,
+ busy: t.sendPage.busy,
+ files: t.web.files,
+ fileName: t.web.fileName,
+ size: t.web.size,
+ dropHint: t.sendTab.placeItems,
+ ),
+ pages: customWebPages,
+ ),
showToken: settings.showToken,
),
);
@@ -218,9 +218,7 @@ class ServerService extends Notifier<ServerState?> {
port: port,
https: https,
session: null,
- webSendState: webSendState,
- webUpload: webUpload,
- webPin: webSendState != null || webUpload ? webPin : null,
+ web: web,
);
state = newServerState;
@@ -246,12 +244,10 @@ class ServerService extends Notifier<ServerState?> {
required String alias,
required int port,
required bool https,
- WebSendState? webSendState,
- bool webUpload = false,
- String? webPin,
+ WebShareState? web,
}) async {
await stopServer();
- return await startServer(alias: alias, port: port, https: https, webSendState: webSendState, webUpload: webUpload, webPin: webPin);
+ return await startServer(alias: alias, port: port, https: https, web: web);
}
Future<void> acceptFileRequest(Map<String, String> fileNameMap) async {
@@ -282,24 +278,30 @@ class ServerService extends Notifier<ServerState?> {
_receiveController.closeSession();
}
- /// Restarts the server with web send (the download API) enabled for [files].
- /// The auto accept setting of a previous web send state is kept.
- Future<void> restartServerWithWebSend({
+ /// Restarts the server with web download (the download API) enabled for [files].
+ /// The auto accept setting of a previous web download state is kept.
+ Future<void> restartServerWithWebDownload({
required String alias,
required int port,
required bool https,
required List<CrossFile> files,
- String? webPin,
+ String? pin,
}) async {
- final webSendState = await _sendController.buildWebSendState(files: files);
- await restartServer(alias: alias, port: port, https: https, webSendState: webSendState, webPin: webPin);
+ final webDownloadState = await _sendController.buildWebDownloadState(files: files);
+ await restartServer(
+ alias: alias,
+ port: port,
+ https: https,
+ web: WebShareDownload(state: webDownloadState, pin: pin),
+ );
}
/// Updates the pin of the active web share mode (download or upload page).
/// The pin is enforced by the Rust server, so the server is restarted.
Future<void> setWebPin(String? pin) async {
final current = state;
- if (current == null || (current.webSendState == null && !current.webUpload) || current.webPin == pin) {
+ final web = current?.web;
+ if (current == null || web == null || web.pin == pin) {
return;
}
@@ -307,28 +309,29 @@ class ServerService extends Notifier<ServerState?> {
alias: current.alias,
port: current.port,
https: current.https,
- webSendState: current.webSendState?.copyWith(sessions: {}),
- webUpload: current.webUpload,
- webPin: pin,
+ web: switch (web) {
+ // Sessions do not survive a server restart.
+ WebShareDownload(:final state) => WebShareDownload(
+ state: state.copyWith(sessions: {}),
+ pin: pin,
+ ),
+ WebShareUpload() => WebShareUpload(pin: pin),
+ },
);
}
- /// Updates the auto accept setting for web send.
- void setWebSendAutoAccept(bool autoAccept) {
- state = state?.copyWith(
- webSendState: state?.webSendState?.copyWith(
- autoAccept: autoAccept,
- ),
- );
+ /// Updates the auto accept setting for web download.
+ void setWebDownloadAutoAccept(bool autoAccept) {
+ state = state?.updateWebDownloadState((webDownload) => webDownload.copyWith(autoAccept: autoAccept));
}
- /// Accepts the web send request.
- void acceptWebSendRequest(String sessionId) {
+ /// Accepts the web download request.
+ void acceptWebDownloadRequest(String sessionId) {
_sendController.acceptRequest(sessionId);
}
- /// Declines the web send request.
- void declineWebSendRequest(String sessionId) {
+ /// Declines the web download request.
+ void declineWebDownloadRequest(String sessionId) {
_sendController.declineRequest(sessionId);
}
@@ -413,9 +416,14 @@ class ServerService extends Notifier<ServerState?> {
alias: current.alias,
port: current.port,
https: current.https,
- webSendState: current.webSendState?.copyWith(sessions: {}),
- webUpload: current.webUpload,
- webPin: current.webPin,
+ web: switch (current.web) {
+ // Sessions do not survive a server restart.
+ WebShareDownload(:final state, :final pin) => WebShareDownload(
+ state: state.copyWith(sessions: {}),
+ pin: pin,
+ ),
+ final other => other,
+ },
);
} catch (e) {
_logger.severe('Failed to restart the server after its listener failed', e);
diff --git a/app/lib/util/native/web_pages_loader.dart b/app/lib/util/native/web_pages_loader.dart
index 8504f397..f73f9e57 100644
--- a/app/lib/util/native/web_pages_loader.dart
+++ b/app/lib/util/native/web_pages_loader.dart
@@ -10,28 +10,18 @@ final _logger = Logger('WebPagesLoader');
/// Loads custom web pages from the `web` folder next to the executable
/// (e.g. `web/download.html`), so the served pages can be customized without
/// recompiling the app. Pages that are not provided fall back to the assets
-/// embedded in the Rust server.
-///
-/// Returns `null` when no custom page exists (or on mobile platforms where
-/// there is no folder next to the executable).
-Future<WebPages?> loadCustomWebPages() async {
+/// embedded in the Rust server (also on mobile platforms where there is no
+/// folder next to the executable).
+Future<WebPages> loadCustomWebPages() async {
if (!checkPlatformIsDesktop()) {
- return null;
+ return const WebPages();
}
final webDir = path.join(File(Platform.resolvedExecutable).parent.path, 'web');
- final downloadHtml = await _readOptionalFile(path.join(webDir, 'download.html'));
- final uploadHtml = await _readOptionalFile(path.join(webDir, 'upload.html'));
- final error403Html = await _readOptionalFile(path.join(webDir, 'error-403.html'));
-
- if (downloadHtml == null && uploadHtml == null && error403Html == null) {
- return null;
- }
-
return WebPages(
- downloadHtml: downloadHtml,
- uploadHtml: uploadHtml,
- error403Html: error403Html,
+ downloadHtml: await _readOptionalFile(path.join(webDir, 'download.html')),
+ uploadHtml: await _readOptionalFile(path.join(webDir, 'upload.html')),
+ error403Html: await _readOptionalFile(path.join(webDir, 'error-403.html')),
);
}
diff --git a/app/lib/widget/dialogs/qr_dialog.dart b/app/lib/widget/dialogs/qr_dialog.dart
index 40f2ac3a..4550be2c 100644
--- a/app/lib/widget/dialogs/qr_dialog.dart
+++ b/app/lib/widget/dialogs/qr_dialog.dart
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:localsend_app/config/theme.dart';
import 'package:localsend_app/gen/strings.g.dart';
-import 'package:localsend_app/model/state/send/web/web_send_state.dart';
+import 'package:localsend_app/model/state/send/web/web_download_state.dart';
import 'package:localsend_app/provider/network/server/server_provider.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';
import 'package:refena_flutter/refena_flutter.dart';
@@ -10,23 +10,23 @@ import 'package:routerino/routerino.dart';
class QrDialog extends StatelessWidget {
final String data;
final String? label;
- final bool listenIncomingWebSendRequests;
+ final bool listenIncomingWebDownloadRequests;
final String? pin;
const QrDialog({
required this.data,
this.label,
- this.listenIncomingWebSendRequests = false,
+ this.listenIncomingWebDownloadRequests = false,
this.pin,
});
@override
Widget build(BuildContext context) {
- final WebSendState? webSendState;
- if (listenIncomingWebSendRequests) {
- webSendState = context.ref.watch(serverProvider.select((s) => s?.webSendState));
+ final WebDownloadState? webDownloadState;
+ if (listenIncomingWebDownloadRequests) {
+ webDownloadState = context.ref.watch(serverProvider.select((s) => s?.webDownloadState));
} else {
- webSendState = null;
+ webDownloadState = null;
}
return AlertDialog(
@@ -53,10 +53,10 @@ class QrDialog extends StatelessWidget {
),
const SizedBox(height: 10),
Text(label ?? data, textAlign: TextAlign.center),
- if (listenIncomingWebSendRequests && webSendState != null)
+ if (listenIncomingWebDownloadRequests && webDownloadState != null)
Builder(
builder: (context) {
- final pending = webSendState?.sessions.values.fold<int>(0, (prev, curr) => prev + (curr.pending ? 1 : 0)) ?? 0;
+ final pending = webDownloadState?.sessions.values.fold<int>(0, (prev, curr) => prev + (curr.pending ? 1 : 0)) ?? 0;
if (pending != 0) {
return Padding(
padding: const EdgeInsets.only(top: 5),
diff --git a/app/lib/widget/dialogs/zoom_dialog.dart b/app/lib/widget/dialogs/zoom_dialog.dart
index 60afde49..5c193485 100644
--- a/app/lib/widget/dialogs/zoom_dialog.dart
+++ b/app/lib/widget/dialogs/zoom_dialog.dart
@@ -1,19 +1,19 @@
import 'package:flutter/material.dart';
import 'package:localsend_app/config/theme.dart';
import 'package:localsend_app/gen/strings.g.dart';
-import 'package:localsend_app/model/state/send/web/web_send_state.dart';
+import 'package:localsend_app/model/state/send/web/web_download_state.dart';
import 'package:localsend_app/provider/network/server/server_provider.dart';
import 'package:refena_flutter/refena_flutter.dart';
import 'package:routerino/routerino.dart';
class ZoomDialog extends StatelessWidget {
final String label;
- final bool listenIncomingWebSendRequests;
+ final bool listenIncomingWebDownloadRequests;
final String? pin;
const ZoomDialog({
required this.label,
- this.listenIncomingWebSendRequests = false,
+ this.listenIncomingWebDownloadRequests = false,
this.pin,
});
@@ -22,11 +22,11 @@ class ZoomDialog extends StatelessWidget {
final width = MediaQuery.of(context).size.width * .80;
final fontSize = width / 400 * 48;
- final WebSendState? webSendState;
- if (listenIncomingWebSendRequests) {
- webSendState = context.ref.watch(serverProvider.select((s) => s?.webSendState));
+ final WebDownloadState? webDownloadState;
+ if (listenIncomingWebDownloadRequests) {
+ webDownloadState = context.ref.watch(serverProvider.select((s) => s?.webDownloadState));
} else {
- webSendState = null;
+ webDownloadState = null;
}
return AlertDialog(
@@ -56,10 +56,10 @@ class ZoomDialog extends StatelessWidget {
child: Text('🔑 $pin', textAlign: TextAlign.center, style: const TextStyle(fontSize: 100)),
),
),
- if (listenIncomingWebSendRequests && webSendState != null)
+ if (listenIncomingWebDownloadRequests && webDownloadState != null)
Builder(
builder: (context) {
- final pending = webSendState?.sessions.values.fold<int>(0, (prev, curr) => prev + (curr.pending ? 1 : 0)) ?? 0;
+ final pending = webDownloadState?.sessions.values.fold<int>(0, (prev, curr) => prev + (curr.pending ? 1 : 0)) ?? 0;
if (pending != 0) {
return Padding(
padding: const EdgeInsets.only(top: 5),
diff --git a/cli/src/app/mod.rs b/cli/src/app/mod.rs
index aba0b647..e28c4968 100644
--- a/cli/src/app/mod.rs
+++ b/cli/src/app/mod.rs
@@ -16,7 +16,7 @@ use localsend::discovery::{
DEFAULT_DISCOVERY_TIMEOUT, DeviceIdentity, DiscoveryConfig, DiscoveryEvent, DiscoveryHandle,
};
use localsend::http::server::v2::ServerEventV2;
-use localsend::http::server::web::WebSendEvent;
+use localsend::http::server::web::{WebConfig, WebDownloadEvent};
use localsend::http::server::{ServerConfigV2, ServerHandle, start_with_port};
use localsend::model::discovery::ProtocolType;
use localsend::multicast::{DEFAULT_MULTICAST_GROUP, DEFAULT_MULTICAST_GROUP_V6, DEFAULT_PORT};
@@ -64,7 +64,7 @@ struct App {
/// Event senders handed to every (re)started server, so the receivers in
/// [run]'s select loop survive server restarts.
server_tx: mpsc::Sender<ServerEventV2>,
- web_tx: mpsc::Sender<WebSendEvent>,
+ web_tx: mpsc::Sender<WebDownloadEvent>,
/// The active web link mode ("share via link" / "receive via link");
/// `Some` while the server runs in plain-HTTP mode for browsers.
@@ -106,7 +106,7 @@ pub async fn run(args: Args) -> anyhow::Result<()> {
// HTTP server (TLS, like the app, until "share via link" drops it).
let (server_tx, mut server_rx) = mpsc::channel::<ServerEventV2>(16);
- let (web_tx, mut web_rx) = mpsc::channel::<WebSendEvent>(16);
+ let (web_tx, mut web_rx) = mpsc::channel::<WebDownloadEvent>(16);
let (server_stop_tx, server_stop_rx) = oneshot::channel::<()>();
let server = start_with_port(
identity.port,
@@ -118,7 +118,7 @@ pub async fn run(args: Args) -> anyhow::Result<()> {
verify_checksums: true,
event_tx: server_tx.clone(),
}),
- None,
+ WebConfig::default(),
server_stop_rx,
)
.await?;
diff --git a/cli/src/app/web_link.rs b/cli/src/app/web_link.rs
index 678103da..db569c0c 100644
--- a/cli/src/app/web_link.rs
+++ b/cli/src/app/web_link.rs
@@ -9,7 +9,7 @@ use super::App;
use crate::picker::PickerTarget;
use crate::ui::Category;
use crate::util;
-use localsend::http::server::web::{WebConfig, WebI18n, WebPages, WebSendConfig, WebSendEvent};
+use localsend::http::server::web::{WebConfig, WebMode as CoreWebMode, WebDownloadConfig, WebDownloadEvent};
use localsend::http::server::{ServerConfigV2, start_with_port};
use localsend::model::transfer::FileContent;
use qrcode::{EcLevel, QrCode};
@@ -83,13 +83,7 @@ impl App {
);
return;
}
- let web_config = WebConfig {
- send: None,
- upload: true,
- i18n: WebI18n::default(),
- pages: WebPages::default(),
- };
- if let Err(err) = self.restart_server(Some(web_config)).await {
+ if let Err(err) = self.restart_server(CoreWebMode::Upload).await {
self.ui.log(
Category::Receive,
&format!("Receive via link: could not restart the server: {err:#}"),
@@ -118,17 +112,12 @@ impl App {
return;
}
let count = files.len();
- let web_config = WebConfig {
- send: Some(WebSendConfig {
- files,
- pin: None,
- event_tx: self.web_tx.clone(),
- }),
- upload: false,
- i18n: WebI18n::default(),
- pages: WebPages::default(),
- };
- if let Err(err) = self.restart_server(Some(web_config)).await {
+ let web_mode = CoreWebMode::Download(WebDownloadConfig {
+ files,
+ pin: None,
+ event_tx: self.web_tx.clone(),
+ });
+ if let Err(err) = self.restart_server(web_mode).await {
self.ui.log(
Category::Send,
&format!("Share via link: could not restart the server: {err:#}"),
@@ -172,7 +161,7 @@ impl App {
async fn disable_web(&mut self, category: Category, feature: &str) {
self.web = None;
- match self.restart_server(None).await {
+ match self.restart_server(CoreWebMode::Disabled).await {
Ok(()) => self.ui.log(
category,
&format!("{feature} disabled, encryption is back on"),
@@ -187,7 +176,7 @@ impl App {
/// Best effort after a failed plain-HTTP restart: get back to the normal
/// encrypted server.
async fn restore_encrypted_server(&mut self) {
- if let Err(err) = self.restart_server(None).await {
+ if let Err(err) = self.restart_server(CoreWebMode::Disabled).await {
self.ui.log(
Category::Send,
&format!("Could not restore the encrypted server: {err:#}"),
@@ -196,18 +185,18 @@ impl App {
}
/// Stops the running server and starts a fresh one on the same port:
- /// the normal encrypted one, or, when `web_config` is given, a plain-HTTP
+ /// the normal encrypted one, or, when a web page is active, a plain-HTTP
/// one that additionally serves that web page.
- async fn restart_server(&mut self, web_config: Option<WebConfig>) -> anyhow::Result<()> {
+ async fn restart_server(&mut self, web_mode: CoreWebMode) -> anyhow::Result<()> {
if let Some(stop_tx) = self.server_stop_tx.take() {
let _ = stop_tx.send(());
}
let _ = tokio::time::timeout(Duration::from_secs(3), self.server.wait_stopped()).await;
let identity = &self.storage.identity;
- let tls_config = match web_config.is_some() {
- true => None,
- false => Some(identity.tls_config()),
+ let tls_config = match web_mode {
+ CoreWebMode::Disabled => Some(identity.tls_config()),
+ _ => None,
};
let (stop_tx, stop_rx) = oneshot::channel::<()>();
let server = start_with_port(
@@ -220,7 +209,10 @@ impl App {
verify_checksums: true,
event_tx: self.server_tx.clone(),
}),
- web_config,
+ WebConfig {
+ mode: web_mode,
+ ..WebConfig::default()
+ },
stop_rx,
)
.await?;
@@ -229,9 +221,9 @@ impl App {
Ok(())
}
- pub(super) fn handle_web_event(&mut self, event: WebSendEvent) {
+ pub(super) fn handle_web_event(&mut self, event: WebDownloadEvent) {
match event {
- WebSendEvent::PrepareDownload {
+ WebDownloadEvent::PrepareDownload {
ip,
user_agent,
decision_tx,
@@ -247,7 +239,7 @@ impl App {
&format!("Web: {ip} opened the shared link{agent}"),
);
}
- WebSendEvent::FileDownload {
+ WebDownloadEvent::FileDownload {
session_id,
file_id,
file,
diff --git a/packages/core/src/http/server/mod.rs b/packages/core/src/http/server/mod.rs
index 1f8e454f..40bcebaa 100644
--- a/packages/core/src/http/server/mod.rs
+++ b/packages/core/src/http/server/mod.rs
@@ -10,7 +10,7 @@ pub use peer_ip::PeerIp;
use crate::crypto::cert::{fingerprint_from_cert_der, public_key_from_cert_der};
use crate::http::server::internal::{InternalConfig, InternalState};
use crate::http::server::v2::ServerEventV2;
-use crate::http::server::web::{WebConfig, WebI18n, WebPages};
+use crate::http::server::web::{WebConfig, WebShare};
use crate::http::state::ClientInfo;
use common::client_cert_verifier::CustomClientCertVerifier;
use common::error::AppError;
@@ -32,7 +32,7 @@ use std::sync::Arc;
use tokio::sync::{mpsc, oneshot, Mutex};
use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
-use web::WebPageState;
+use web::WebState;
/// Configuration for the v2 (legacy) protocol endpoints.
pub struct ServerConfigV2 {
@@ -71,17 +71,8 @@ pub struct AppState {
/// Information about server's device.
info: Arc<Mutex<ClientInfo>>,
- /// State for serving the download page (web send).
- web: Option<Arc<WebPageState>>,
-
- /// Whether the upload page is served (when the download page is not active).
- web_upload: bool,
-
- /// Translations for the web pages, served via `/i18n.json`.
- web_i18n: Option<Arc<WebI18n>>,
-
- /// The HTML pages served to browsers, falling back to the embedded assets.
- web_pages: Arc<WebPages>,
+ /// Runtime state of the browser-facing pages and web download.
+ web: Arc<WebState>,
/// State for application-internal endpoints.
internal: Option<Arc<InternalState>>,
@@ -101,7 +92,7 @@ impl AppState {
info: Arc<Mutex<ClientInfo>>,
internal_config: Option<InternalConfig>,
v2_config: Option<ServerConfigV2>,
- web_config: Option<WebConfig>,
+ web_config: WebConfig,
) -> Self {
let v2 = v2_config.map(|config| {
Arc::new(V2State {
@@ -113,23 +104,11 @@ impl AppState {
})
});
- let (web, web_upload, web_i18n, web_pages) = match web_config {
- Some(config) => (
- config.send.map(|send| Arc::new(WebPageState::new(send))),
- config.upload,
- Some(Arc::new(config.i18n)),
- Arc::new(config.pages),
- ),
- None => (None, false, None, Arc::new(WebPages::default())),
- };
let internal = internal_config.map(|config| Arc::new(InternalState::new(config)));
Self {
info,
- web,
- web_upload,
- web_i18n,
- web_pages,
+ web: Arc::new(WebState::from(web_config)),
internal,
received_nonce_map: Arc::new(Mutex::new(LruCache::new(
NonZeroUsize::new(200).unwrap(),
@@ -235,7 +214,7 @@ pub async fn start_with_port(
info: ClientInfo,
internal_config: Option<InternalConfig>,
v2_config: Option<ServerConfigV2>,
- web_config: Option<WebConfig>,
+ web_config: WebConfig,
stop_rx: oneshot::Receiver<()>,
) -> anyhow::Result<ServerHandle> {
// Installed before returning, so that a client built right after (which
@@ -391,7 +370,7 @@ async fn start_server_with_listener(
) -> anyhow::Result<()> {
// Browsers have no client certificate, so presenting one is optional while
// the web pages are served. A certificate that is presented is still verified.
- let mandatory_client_auth = app_state.web.is_none() && !app_state.web_upload;
+ let mandatory_client_auth = matches!(app_state.web.share, WebShare::Disabled);
let tls_acceptor = match tls_config {
Some(tls_config) => Some(
diff --git a/packages/core/src/http/server/v2.rs b/packages/core/src/http/server/v2.rs
index da66ad95..9d034a74 100644
--- a/packages/core/src/http/server/v2.rs
+++ b/packages/core/src/http/server/v2.rs
@@ -191,7 +191,7 @@ pub(crate) async fn register(
}
let info = state.info.lock().await.clone();
- let download = state.web.is_some();
+ let download = state.web.share.download().is_some();
Ok(JsonResponse {
status: StatusCode::OK,
@@ -208,7 +208,7 @@ pub(crate) async fn register(
pub(crate) async fn info(state: AppState) -> Result<JsonResponse<InfoResponseDtoV2>, AppError> {
let info = state.info.lock().await.clone();
- let download = state.web.is_some();
+ let download = state.web.share.download().is_some();
Ok(JsonResponse {
status: StatusCode::OK,
diff --git a/packages/core/src/http/server/v3.rs b/packages/core/src/http/server/v3.rs
index f88103e7..71fc561d 100644
--- a/packages/core/src/http/server/v3.rs
+++ b/packages/core/src/http/server/v3.rs
@@ -59,7 +59,7 @@ pub(crate) async fn register(
let payload = body.collect_to_json::<RegisterDto>().await?;
let info = state.info.lock().await.clone();
- let has_web_interface = state.web.is_some();
+ let has_web_interface = state.web.share.download().is_some();
Ok(JsonResponse {
status: StatusCode::OK,
diff --git a/packages/core/src/http/server/web.rs b/packages/core/src/http/server/web.rs
index 3feaa321..10bd8715 100644
--- a/packages/core/src/http/server/web.rs
+++ b/packages/core/src/http/server/web.rs
@@ -22,10 +22,10 @@ use tokio::sync::{mpsc, oneshot, Mutex};
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;
-/// Events emitted by the web send (download API) endpoints that must be handled
-/// by the application. Web send can be enabled independently of the v2 endpoints.
+/// Events emitted by the web download (download API) endpoints that must be handled
+/// by the application. Web download can be enabled independently of the v2 endpoints.
#[derive(Debug)]
-pub enum WebSendEvent {
+pub enum WebDownloadEvent {
/// A web client requests to download the shared files
/// via `POST /api/localsend/v2/prepare-download`.
///
@@ -84,16 +84,11 @@ const FILE_NAME_ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
.remove(b'(')
.remove(b')');
-/// Configuration for the web pages served to browsers.
+/// Configuration for the pages served to browsers.
+#[derive(Default)]
pub struct WebConfig {
- /// Enables web send (the download page): files offered for download by web browsers.
- /// `None` disables the download page and the download API.
- pub send: Option<WebSendConfig>,
-
- /// Serves the upload page so web browsers can upload files
- /// via the v2 `prepare-upload`/`upload` endpoints.
- /// Ignored when [`WebConfig::send`] is set: the download page takes precedence at `/`.
- pub upload: bool,
+ /// What is served at `/` and which browser-facing API is active.
+ pub mode: WebMode,
/// Translations for the web pages, served via `/i18n.json`.
pub i18n: WebI18n,
@@ -103,6 +98,25 @@ pub struct WebConfig {
pub pages: WebPages,
}
+/// What is served at `/` and which browser-facing API is active.
+/// The modes are mutually exclusive: only one page can live at `/`.
+#[derive(Default)]
+pub enum WebMode {
+ /// No web share active: `/` serves the 403 page and client certificates
+ /// are mandatory under TLS, so the 403 page is effectively only reachable
+ /// when encryption is off.
+ #[default]
+ Disabled,
+
+ /// Web download: the download page and the download API,
+ /// offering the configured files for download by web browsers.
+ Download(WebDownloadConfig),
+
+ /// The upload page: web browsers upload files
+ /// via the v2 `prepare-upload`/`upload` endpoints.
+ Upload,
+}
+
/// The HTML pages served to browsers.
///
/// Each page is optional: a `None` page is served from the corresponding
@@ -110,31 +124,31 @@ pub struct WebConfig {
/// they customize.
#[derive(Clone, Debug, Default)]
pub struct WebPages {
- /// The download page served at `/` while web send is active.
+ /// The download page served at `/` while web download is active.
pub download_html: Option<String>,
/// The upload page served at `/` while the upload page is enabled.
pub upload_html: Option<String>,
- /// The error page served at `/` when neither page is active.
+ /// The error page served at `/` in [`WebMode::Disabled`].
pub error_403_html: Option<String>,
}
-/// Configuration for web send (download API): files offered for download by web browsers.
+/// Configuration for web download (download API): files offered for download by web browsers.
///
-/// Web send can be enabled independently of the v2/v3 protocol endpoints.
-pub struct WebSendConfig {
+/// Web download can be enabled independently of the v2/v3 protocol endpoints.
+pub struct WebDownloadConfig {
/// The metadata of the files offered for download, mapped by file ID.
///
/// The content is requested from the application per download
- /// via [`WebSendEvent::FileDownload`].
+ /// via [`WebDownloadEvent::FileDownload`].
pub files: HashMap<String, FileDto>,
/// Optional PIN that web clients must provide via the `pin` query parameter.
pub pin: Option<String>,
/// Channel on which the server emits events that must be handled by the application.
- pub event_tx: mpsc::Sender<WebSendEvent>,
+ pub event_tx: mpsc::Sender<WebDownloadEvent>,
}
/// Translations for the web pages, served via `/i18n.json`.
@@ -172,8 +186,8 @@ impl Default for WebI18n {
}
}
-/// Runtime state of the web send (download API) endpoints.
-pub(crate) struct WebPageState {
+/// Runtime state of the web download (download API) endpoints.
+pub(crate) struct WebDownloadState {
/// The metadata of the files offered for download, mapped by file ID.
pub(crate) files: HashMap<String, FileDto>,
@@ -181,17 +195,17 @@ pub(crate) struct WebPageState {
pub(crate) pin: Option<String>,
/// Channel on which server events are emitted to the application.
- pub(crate) event_tx: mpsc::Sender<WebSendEvent>,
+ pub(crate) event_tx: mpsc::Sender<WebDownloadEvent>,
/// Download sessions, keyed by session ID (the client's IP address).
- pub(crate) sessions: Mutex<HashMap<String, WebSendSession>>,
+ pub(crate) sessions: Mutex<HashMap<String, WebDownloadSession>>,
/// Maps client IPs to the number of failed PIN attempts.
pub(crate) pin_attempts: Mutex<LruCache<IpAddr, u32>>,
}
-impl WebPageState {
- pub(crate) fn new(config: WebSendConfig) -> Self {
+impl WebDownloadState {
+ pub(crate) fn new(config: WebDownloadConfig) -> Self {
Self {
files: config.files,
pin: config.pin,
@@ -202,8 +216,65 @@ impl WebPageState {
}
}
+/// Runtime counterpart of [`WebConfig`].
+pub(crate) struct WebState {
+ /// Which web share is active, holding the runtime state for web download.
+ pub(crate) share: WebShare,
+
+ /// Translations for the web pages, served via `/i18n.json`.
+ pub(crate) i18n: WebI18n,
+
+ /// The HTML pages served to browsers, falling back to the embedded assets.
+ pub(crate) pages: WebPages,
+}
+
+impl From<WebConfig> for WebState {
+ fn from(config: WebConfig) -> Self {
+ Self {
+ share: config.mode.into(),
+ i18n: config.i18n,
+ pages: config.pages,
+ }
+ }
+}
+
+/// Which web share is active, mirroring [`WebMode`] with the runtime state
+/// for web download attached.
+pub(crate) enum WebShare {
+ /// No web share active: `/` serves the 403 page.
+ Disabled,
+
+ /// Web download: the download page, with its runtime session state.
+ Download(Arc<WebDownloadState>),
+
+ /// The upload page.
+ Upload,
+}
+
+impl WebShare {
+ /// The web-download runtime state, when web download is active.
+ pub(crate) fn download(&self) -> Option<&Arc<WebDownloadState>> {
+ match self {
+ WebShare::Download(download) => Some(download),
+ WebShare::Disabled | WebShare::Upload => None,
+ }
+ }
+}
+
+impl From<WebMode> for WebShare {
+ fn from(mode: WebMode) -> Self {
+ match mode {
+ WebMode::Disabled => WebShare::Disabled,
+ WebMode::Download(download) => {
+ WebShare::Download(Arc::new(WebDownloadState::new(download)))
+ }
+ WebMode::Upload => WebShare::Upload,
+ }
+ }
+}
+
/// A download session of a single web client.
-pub(crate) struct WebSendSession {
+pub(crate) struct WebDownloadSession {
/// The IP address of the web client. Downloads are only allowed from this address.
ip: PeerIp,
@@ -212,35 +283,26 @@ pub(crate) struct WebSendSession {
}
pub(crate) fn index(state: &AppState) -> Response<BoxedBody> {
- let pages = state.web_pages.as_ref();
- if state.web.is_some() {
- html_response(
+ let pages = &state.web.pages;
+ match &state.web.share {
+ WebShare::Download(_) => html_response(
StatusCode::OK,
pages.download_html.as_deref().unwrap_or(DOWNLOAD_HTML),
"text/html; charset=utf-8",
- )
- } else if state.web_upload {
- html_response(
+ ),
+ WebShare::Upload => html_response(
StatusCode::OK,
pages.upload_html.as_deref().unwrap_or(UPLOAD_HTML),
"text/html; charset=utf-8",
- )
- } else {
- error_403_page(pages)
+ ),
+ WebShare::Disabled => error_403_page(pages),
}
}
pub(crate) fn i18n(state: &AppState) -> Result<Response<BoxedBody>, AppError> {
- let Some(i18n) = &state.web_i18n else {
- return Err(AppError::Message(
- StatusCode::FORBIDDEN,
- "Web pages not initialized.".to_string(),
- ));
- };
-
Ok(JsonResponse {
status: StatusCode::OK,
- body: i18n.as_ref(),
+ body: &state.web.i18n,
}
.into_response())
}
@@ -285,7 +347,7 @@ pub(crate) async fn prepare_download(
let mut sessions = web.sessions.lock().await;
sessions.insert(
session_id.clone(),
- WebSendSession {
+ WebDownloadSession {
ip: client_info.ip,
accepted: false,
},
@@ -297,7 +359,7 @@ pub(crate) async fn prepare_download(
let mut pending_guard = PendingWebSessionGuard::new(web.clone(), session_id.clone());
let (decision_tx, decision_rx) = oneshot::channel();
- let event = WebSendEvent::PrepareDownload {
+ let event = WebDownloadEvent::PrepareDownload {
ip: client_info.ip,
session_id: session_id.clone(),
user_agent,
@@ -370,7 +432,7 @@ pub(crate) async fn download(
// The application provides the file content as a stream of bytes.
let (content_tx, content_rx) = oneshot::channel::<FileContent>();
- let event = WebSendEvent::FileDownload {
+ let event = WebDownloadEvent::FileDownload {
session_id: session_id.clone(),
file_id: file_id.clone(),
file: file.clone(),
@@ -407,10 +469,10 @@ pub(crate) async fn download(
Ok(response)
}
-fn require_web(state: &AppState) -> Result<Arc<WebPageState>, AppError> {
- state.web.clone().ok_or(AppError::Message(
+fn require_web(state: &AppState) -> Result<Arc<WebDownloadState>, AppError> {
+ state.web.share.download().cloned().ok_or(AppError::Message(
StatusCode::FORBIDDEN,
- "Web send not initialized.".to_string(),
+ "Web download not initialized.".to_string(),
))
}
@@ -438,7 +500,7 @@ fn error_403_page(pages: &WebPages) -> Response<BoxedBody> {
async fn file_list_response(
state: &AppState,
- web: &WebPageState,
+ web: &WebDownloadState,
session_id: String,
) -> Response<BoxedBody> {
let info = state.info.lock().await.clone();
@@ -474,13 +536,13 @@ fn receiver_stream_body(binary_rx: mpsc::Receiver<Bytes>) -> BoxedBody {
/// when the request future is cancelled (e.g. the web client disconnected
/// while the application was still deciding).
struct PendingWebSessionGuard {
- web: Arc<WebPageState>,
+ web: Arc<WebDownloadState>,
session_id: String,
armed: bool,
}
impl PendingWebSessionGuard {
- fn new(web: Arc<WebPageState>, session_id: String) -> Self {
+ fn new(web: Arc<WebDownloadState>, session_id: String) -> Self {
Self {
web,
session_id,
@@ -513,7 +575,7 @@ impl Drop for PendingWebSessionGuard {
}
}
-async fn clear_pending_session(web: &WebPageState, session_id: &str) {
+async fn clear_pending_session(web: &WebDownloadState, session_id: &str) {
let mut sessions = web.sessions.lock().await;
if sessions
.get(session_id)
diff --git a/packages/core/tests/accept_resilience.rs b/packages/core/tests/accept_resilience.rs
index 0e61cacc..94b2001d 100644
--- a/packages/core/tests/accept_resilience.rs
+++ b/packages/core/tests/accept_resilience.rs
@@ -10,6 +10,7 @@
//! is the only test in this binary.
use localsend::http::server::v2::ServerEventV2;
+use localsend::http::server::web::WebConfig;
use localsend::http::server::{start_with_port, ServerConfigV2};
use localsend::http::state::ClientInfo;
use std::time::Duration;
@@ -83,7 +84,7 @@ async fn server_survives_descriptor_exhaustion() {
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
diff --git a/packages/core/tests/discovery.rs b/packages/core/tests/discovery.rs
index c577e857..cc4d1d9d 100644
--- a/packages/core/tests/discovery.rs
+++ b/packages/core/tests/discovery.rs
@@ -12,6 +12,7 @@ use localsend::crypto::cert::generate_self_signed;
use localsend::discovery::{
self, DeviceIdentity, DiscoveryConfig, DiscoveryEvent, DiscoveryHandle,
};
+use localsend::http::server::web::WebConfig;
use localsend::http::server::{start_with_port, ServerConfigV2, TlsConfig};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::{DeviceType, ProtocolType, PROTOCOL_VERSION_V2};
@@ -74,7 +75,7 @@ async fn start_register_server(
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
diff --git a/packages/core/tests/event_backpressure.rs b/packages/core/tests/event_backpressure.rs
index cc2e2c44..d374c7f0 100644
--- a/packages/core/tests/event_backpressure.rs
+++ b/packages/core/tests/event_backpressure.rs
@@ -13,6 +13,7 @@ use localsend::discovery::{self, DeviceIdentity, DiscoveryConfig, DiscoveryEvent
use localsend::http::client::LsHttpClientV2;
use localsend::http::dto_v2::RegisterDtoV2;
use localsend::http::server::v2::ServerEventV2;
+use localsend::http::server::web::WebConfig;
use localsend::http::server::{start_with_port, ServerConfigV2};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::{DeviceType, ProtocolType, PROTOCOL_VERSION_V2};
@@ -65,7 +66,7 @@ async fn start_server_with_stalled_events(
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
diff --git a/packages/core/tests/internal_server.rs b/packages/core/tests/internal_server.rs
index b44df4f3..32f69ebd 100644
--- a/packages/core/tests/internal_server.rs
+++ b/packages/core/tests/internal_server.rs
@@ -2,6 +2,7 @@
use localsend::http::server::internal::{InternalConfig, InternalEvent};
use localsend::http::server::start_with_port;
+use localsend::http::server::web::WebConfig;
use localsend::http::state::ClientInfo;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot, Mutex};
@@ -47,7 +48,7 @@ async fn start_test_server(internal_enabled: bool) -> TestServer {
},
internal_config,
None,
- None,
+ WebConfig::default(),
stop_rx,
)
.await
diff --git a/packages/core/tests/v2_server.rs b/packages/core/tests/v2_server.rs
index cccd518e..aaf7f1dc 100644
--- a/packages/core/tests/v2_server.rs
+++ b/packages/core/tests/v2_server.rs
@@ -7,6 +7,7 @@ use localsend::http::client::{ClientError, LsHttpClientV2};
use localsend::http::dto_v2::{PrepareUploadRequestDtoV2, RegisterDtoV2};
use localsend::http::server::common::save::FileUploadTarget;
use localsend::http::server::v2::{PrepareUploadDecisionV2, ServerEventV2, SessionEndReasonV2};
+use localsend::http::server::web::WebConfig;
use localsend::http::server::{start_with_port, ServerConfigV2};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::ProtocolType;
@@ -141,7 +142,7 @@ async fn start_test_server_with_verification(
verify_checksums,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
@@ -974,7 +975,7 @@ async fn test_prepare_upload_aborted_by_sender_disconnect() {
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
@@ -1076,7 +1077,7 @@ async fn test_prepare_upload_cancelled_by_session_less_cancel() {
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
@@ -1211,7 +1212,7 @@ async fn test_prepare_upload_aborted_by_sender_disconnect_tls() {
verify_checksums: true,
event_tx,
}),
- None,
+ WebConfig::default(),
stop_rx,
)
.await
diff --git a/packages/core/tests/v2_tls_pinning.rs b/packages/core/tests/v2_tls_pinning.rs
index a3ccc0de..285074ce 100644
--- a/packages/core/tests/v2_tls_pinning.rs
+++ b/packages/core/tests/v2_tls_pinning.rs
@@ -9,7 +9,7 @@ use localsend::http::client::{ClientError, LsHttpClientV2};
use localsend::http::dto_v2::{PrepareUploadRequestDtoV2, RegisterDtoV2};
use localsend::http::server::common::save::FileUploadTarget;
use localsend::http::server::v2::{PrepareUploadDecisionV2, ServerEventV2};
-use localsend::http::server::web::{WebConfig, WebI18n, WebPages};
+use localsend::http::server::web::{WebConfig, WebMode};
use localsend::http::server::{start_with_port, ServerConfigV2, TlsConfig};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::ProtocolType;
@@ -49,12 +49,12 @@ struct TestServer {
/// Starts a test server over TLS using the given identity.
async fn start_tls_server(identity: &Identity) -> TestServer {
- start_tls_server_with_web(identity, None).await
+ start_tls_server_with_web(identity, WebConfig::default()).await
}
/// Starts a test server over TLS, optionally with the web pages enabled
/// (which makes the client certificate optional).
-async fn start_tls_server_with_web(identity: &Identity, web: Option<WebConfig>) -> TestServer {
+async fn start_tls_server_with_web(identity: &Identity, web: WebConfig) -> TestServer {
let _ = tracing_subscriber::fmt().with_test_writer().try_init();
let prepare_uploads: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
let received: Arc<Mutex<Vec<(String, Vec<u8>)>>> = Arc::new(Mutex::new(Vec::new()));
@@ -373,12 +373,10 @@ async fn test_client_without_cert_allowed_in_web_mode() {
let sender = generate_identity();
let server = start_tls_server_with_web(
&server_identity,
- Some(WebConfig {
- send: None,
- upload: true,
- i18n: WebI18n::default(),
- pages: WebPages::default(),
- }),
+ WebConfig {
+ mode: WebMode::Upload,
+ ..WebConfig::default()
+ },
)
.await;
diff --git a/packages/core/tests/v2_web_send.rs b/packages/core/tests/v2_web_download.rs
similarity index 89%
rename from packages/core/tests/v2_web_send.rs
rename to packages/core/tests/v2_web_download.rs
index 418c1192..4a98d821 100644
--- a/packages/core/tests/v2_web_send.rs
+++ b/packages/core/tests/v2_web_download.rs
@@ -3,8 +3,8 @@
use bytes::Bytes;
use localsend::http::client::{ClientError, LsHttpClientV2};
use localsend::http::server::v2::ServerEventV2;
-use localsend::http::server::web::WebSendConfig;
-use localsend::http::server::web::{WebConfig, WebI18n, WebPages, WebSendEvent};
+use localsend::http::server::web::WebDownloadConfig;
+use localsend::http::server::web::{WebConfig, WebDownloadEvent, WebMode, WebPages};
use localsend::http::server::{start_with_port, ServerConfigV2};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::ProtocolType;
@@ -64,30 +64,30 @@ impl TestFileContent {
}
async fn start_test_server(
- web_send: Option<(WebSendConfig, HashMap<String, TestFileContent>)>,
+ web_download: Option<(WebDownloadConfig, HashMap<String, TestFileContent>)>,
accept: bool,
) -> TestServer {
let _ = tracing_subscriber::fmt().with_test_writer().try_init();
let prepare_download_events = Arc::new(AtomicU32::new(0));
- let (web_send, contents) = match web_send {
+ let (web_download, contents) = match web_download {
Some((config, contents)) => (Some(config), contents),
None => (None, HashMap::new()),
};
- // Web send emits its own event type, independent of the v2 protocol events.
- let (web_event_tx, mut web_event_rx) = mpsc::channel::<WebSendEvent>(16);
+ // Web download emits its own event type, independent of the v2 protocol events.
+ let (web_event_tx, mut web_event_rx) = mpsc::channel::<WebDownloadEvent>(16);
tokio::spawn({
let prepare_download_events = prepare_download_events.clone();
async move {
while let Some(event) = web_event_rx.recv().await {
match event {
- WebSendEvent::PrepareDownload { decision_tx, .. } => {
+ WebDownloadEvent::PrepareDownload { decision_tx, .. } => {
prepare_download_events.fetch_add(1, Ordering::SeqCst);
let _ = decision_tx.send(accept);
}
- WebSendEvent::FileDownload {
+ WebDownloadEvent::FileDownload {
file_id,
content_tx,
..
@@ -115,16 +115,17 @@ async fn start_test_server(
let (stop_tx, stop_rx) = oneshot::channel::<()>();
- // Web send is configured independently of the v2 endpoints.
- let web_config = web_send.map(|mut config| {
- config.event_tx = web_event_tx;
- WebConfig {
- send: Some(config),
- upload: false,
- i18n: WebI18n::default(),
- pages: WebPages::default(),
+ // Web download is configured independently of the v2 endpoints.
+ let web_config = match web_download {
+ Some(mut config) => {
+ config.event_tx = web_event_tx;
+ WebConfig {
+ mode: WebMode::Download(config),
+ ..WebConfig::default()
+ }
}
- });
+ None => WebConfig::default(),
+ };
// Port 0 lets the OS pick a free port, avoiding collisions between tests.
let handle = start_with_port(
@@ -168,21 +169,21 @@ fn file_dto(id: &str, name: &str, size: u64) -> FileDto {
}
}
-/// Creates a web send config with an in-memory text file and a file on disk.
+/// Creates a web download config with an in-memory text file and a file on disk.
///
/// Returns the config, the content sources for the test event handler and
/// the path of the file on disk (the caller should delete it).
-fn web_send_config(
+fn web_download_config(
pin: Option<String>,
) -> (
- WebSendConfig,
+ WebDownloadConfig,
HashMap<String, TestFileContent>,
PathBuf,
Vec<u8>,
) {
let disk_content: Vec<u8> = (0..100_000u32).map(|i| i as u8).collect();
let disk_path =
- std::env::temp_dir().join(format!("localsend-web-send-{}", uuid::Uuid::new_v4()));
+ std::env::temp_dir().join(format!("localsend-web-download-{}", uuid::Uuid::new_v4()));
std::fs::write(&disk_path, &disk_content).expect("Failed to write test file");
// The config only carries the metadata; the content is streamed by the
@@ -210,11 +211,11 @@ fn web_send_config(
]);
// The event channel is a placeholder; `start_test_server` replaces it with
- // the one whose receiver handles the web send events.
- let (event_tx, _event_rx) = tokio::sync::mpsc::channel::<WebSendEvent>(16);
+ // the one whose receiver handles the web download events.
+ let (event_tx, _event_rx) = tokio::sync::mpsc::channel::<WebDownloadEvent>(16);
(
- WebSendConfig {
+ WebDownloadConfig {
files,
pin,
event_tx,
@@ -235,7 +236,7 @@ fn assert_status(result: Result<impl Sized, ClientError>, expected_status: u16)
#[tokio::test]
async fn test_web_page() {
- let (config, contents, disk_path, _) = web_send_config(None);
+ let (config, contents, disk_path, _) = web_download_config(None);
let server = start_test_server(Some((config, contents)), true).await;
let client = localsend::reqwest::Client::new();
let base_url = format!("http://127.0.0.1:{}", server.port);
@@ -313,12 +314,10 @@ async fn test_upload_page() {
verify_checksums: true,
event_tx: v2_event_tx,
}),
- Some(WebConfig {
- send: None,
- upload: true,
- i18n: WebI18n::default(),
- pages: WebPages::default(),
- }),
+ WebConfig {
+ mode: WebMode::Upload,
+ ..WebConfig::default()
+ },
stop_rx,
)
.await
@@ -328,13 +327,13 @@ async fn test_upload_page() {
let client = localsend::reqwest::Client::new();
let base_url = format!("http://127.0.0.1:{port}");
- // The upload page is served at `/` because web send is not active.
+ // The upload page is served at `/` because web download is not active.
let response = client.get(&base_url).send().await.unwrap();
assert_eq!(response.status().as_u16(), 200);
let body = response.text().await.unwrap();
assert!(body.contains("LocalSend"));
assert!(body.contains("prepare-upload"));
- // The download page is not served without web send.
+ // The download page is not served without web download.
assert!(!body.contains("prepare-download"));
let response = client
@@ -370,16 +369,15 @@ async fn test_custom_web_pages() {
verify_checksums: true,
event_tx: v2_event_tx,
}),
- Some(WebConfig {
- send: None,
- upload: true,
- i18n: WebI18n::default(),
+ WebConfig {
+ mode: WebMode::Upload,
pages: WebPages {
download_html: None,
upload_html: Some("<html>custom upload page</html>".to_string()),
error_403_html: None,
},
- }),
+ ..WebConfig::default()
+ },
stop_rx,
)
.await
@@ -400,7 +398,7 @@ async fn test_custom_web_pages() {
#[tokio::test]
async fn test_full_download_flow() {
- let (config, contents, disk_path, disk_content) = web_send_config(None);
+ let (config, contents, disk_path, disk_content) = web_download_config(None);
let server = start_test_server(Some((config, contents)), true).await;
let client = LsHttpClientV2::try_new_without_cert().unwrap();
@@ -472,7 +470,7 @@ async fn test_full_download_flow() {
#[tokio::test]
async fn test_prepare_download_rejected() {
- let (config, contents, disk_path, _) = web_send_config(None);
+ let (config, contents, disk_path, _) = web_download_config(None);
let server = start_test_server(Some((config, contents)), false).await;
let client = LsHttpClientV2::try_new_without_cert().unwrap();
@@ -499,7 +497,7 @@ async fn test_prepare_download_rejected() {
#[tokio::test]
async fn test_download_invalid_session() {
- let (config, contents, disk_path, _) = web_send_config(None);
+ let (config, contents, disk_path, _) = web_download_config(None);
let server = start_test_server(Some((config, contents)), true).await;
let client = LsHttpClientV2::try_new_without_cert().unwrap();
@@ -535,7 +533,7 @@ async fn test_download_invalid_session() {
#[tokio::test]
async fn test_pin() {
- let (config, contents, disk_path, _) = web_send_config(Some("123456".to_string()));
+ let (config, contents, disk_path, _) = web_download_config(Some("123456".to_string()));
let server = start_test_server(Some((config, contents)), true).await;
let client = LsHttpClientV2::try_new_without_cert().unwrap();
@@ -574,7 +572,7 @@ async fn test_pin() {
#[tokio::test]
async fn test_pin_too_many_attempts() {
- let (config, contents, disk_path, _) = web_send_config(Some("123456".to_string()));
+ let (config, contents, disk_path, _) = web_download_config(Some("123456".to_string()));
let server = start_test_server(Some((config, contents)), true).await;
let client = LsHttpClientV2::try_new_without_cert().unwrap();
diff --git a/packages/localsend_isolates/lib/rust/api/server.dart b/packages/localsend_isolates/lib/rust/api/server.dart
index eb5c5088..c119a38b 100644
--- a/packages/localsend_isolates/lib/rust/api/server.dart
+++ b/packages/localsend_isolates/lib/rust/api/server.dart
@@ -16,9 +16,10 @@ part 'server.freezed.dart';
/// Starts the HTTP server on the given port (IPv4 and IPv6).
/// The server runs until [RsHttpServer::stop] is called.
///
-/// Passing [web] additionally serves the web pages: the download page when
-/// [WebParams::send] is set (so web browsers can download the offered files)
-/// or the upload page when [WebParams::upload] is enabled.
+/// [web] configures the pages served to browsers: [WebParams::mode] selects
+/// the download page ([WebMode::Download], so web browsers can download the
+/// offered files), the upload page ([WebMode::Upload]) or no web share at all
+/// ([WebMode::Disabled], serving the 403 page).
///
/// Passing [show_token] enables the internal `show` endpoint that lets another
/// application instance request this one to show itself (emitted as
@@ -35,7 +36,7 @@ Future<RsHttpServer> startServer({
required String fingerprint,
String? pin,
required bool verifyChecksums,
- WebParams? web,
+ required WebParams web,
String? showToken,
}) => RustLib.instance.api.crateApiServerStartServer(
port: port,
@@ -79,7 +80,7 @@ abstract class RsHttpServer implements RustOpaqueInterface {
/// Emits server events until the server is stopped.
/// Can only be listened to once.
///
- /// The v2 protocol, the web send (download API), and the internal endpoint
+ /// The v2 protocol, the web download (download API), and the internal endpoint
/// events are all emitted on the same stream.
///
/// Also returns when the Dart side of the stream is gone (e.g. after a
@@ -344,6 +345,33 @@ class WebI18n {
dropHint == other.dropHint;
}
+@freezed
+sealed class WebMode with _$WebMode {
+ const WebMode._();
+
+ /// No web share active: `/` serves the 403 page and client certificates
+ /// are mandatory under TLS, so the 403 page is effectively only reachable
+ /// when encryption is off.
+ const factory WebMode.disabled() = WebMode_Disabled;
+
+ /// Web download: the download page and the download API, offering files for
+ /// download by web browsers.
+ ///
+ /// Web download can be enabled independently of the v2 protocol endpoints.
+ const factory WebMode.download({
+ /// The metadata of the files offered for download, mapped by file ID.
+ /// The content is requested per download via [RsServerEvent::WebFileDownload].
+ required Map<String, FileDto> files,
+
+ /// Optional PIN that web clients must provide via the `pin` query parameter.
+ String? pin,
+ }) = WebMode_Download;
+
+ /// The upload page: web browsers upload files via the v2
+ /// `prepare-upload`/`upload` endpoints.
+ const factory WebMode.upload() = WebMode_Upload;
+}
+
class WebPages {
final String? downloadHtml;
final String? uploadHtml;
@@ -368,67 +396,31 @@ class WebPages {
error403Html == other.error403Html;
}
-/// Configuration for the web pages served to browsers. When omitted, the web
-/// pages respond with 403 and only the v2 endpoints run.
+/// Configuration for the pages served to browsers. Always part of the server
+/// configuration: even with web share disabled ([WebMode::Disabled]), the
+/// server serves the 403 page at `/`.
class WebParams {
- /// Enables web send (the download page): files offered for download by web
- /// browsers. `null` disables the download page and the download API.
- final WebSendParams? send;
-
- /// Serves the upload page so web browsers can upload files via the v2
- /// `prepare-upload`/`upload` endpoints. Ignored when [WebParams::send] is
- /// set: the download page takes precedence at `/`.
- final bool upload;
+ /// What is served at `/` and which browser-facing API is active.
+ final WebMode mode;
/// Translations for the web pages, served via `/i18n.json`.
final WebI18n i18N;
/// Custom HTML pages replacing the embedded web pages.
- /// Pages left `null` (or the whole struct being `null`) are served from
- /// the assets embedded at compile time.
- final WebPages? pages;
+ /// Pages left `null` are served from the assets embedded at compile time.
+ final WebPages pages;
const WebParams({
- this.send,
- required this.upload,
+ required this.mode,
required this.i18N,
- this.pages,
+ required this.pages,
});
@override
- int get hashCode => send.hashCode ^ upload.hashCode ^ i18N.hashCode ^ pages.hashCode;
+ int get hashCode => mode.hashCode ^ i18N.hashCode ^ pages.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
- other is WebParams &&
- runtimeType == other.runtimeType &&
- send == other.send &&
- upload == other.upload &&
- i18N == other.i18N &&
- pages == other.pages;
-}
-
-/// Configuration for web send: files offered for download by web browsers.
-///
-/// Web send can be enabled independently of the v2 protocol endpoints.
-class WebSendParams {
- /// The metadata of the files offered for download, mapped by file ID.
- /// The content is requested per download via [RsServerEvent::WebFileDownload].
- final Map<String, FileDto> files;
-
- /// Optional PIN that web clients must provide via the `pin` query parameter.
- final String? pin;
-
- const WebSendParams({
- required this.files,
- this.pin,
- });
-
- @override
- int get hashCode => files.hashCode ^ pin.hashCode;
-
- @override
- bool operator ==(Object other) =>
- identical(this, other) || other is WebSendParams && runtimeType == other.runtimeType && files == other.files && pin == other.pin;
+ other is WebParams && runtimeType == other.runtimeType && mode == other.mode && i18N == other.i18N && pages == other.pages;
}
diff --git a/packages/localsend_isolates/lib/rust/api/server.freezed.dart b/packages/localsend_isolates/lib/rust/api/server.freezed.dart
index c9906d8d..8d1e6fee 100644
--- a/packages/localsend_isolates/lib/rust/api/server.freezed.dart
+++ b/packages/localsend_isolates/lib/rust/api/server.freezed.dart
@@ -925,4 +925,313 @@ as String,
}
+/// @nodoc
+mixin _$WebMode {
+
+
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is WebMode);
+}
+
+
+@override
+int get hashCode => runtimeType.hashCode;
+
+@override
+String toString() {
+ return 'WebMode()';
+}
+
+
+}
+
+/// @nodoc
+class $WebModeCopyWith<$Res> {
+$WebModeCopyWith(WebMode _, $Res Function(WebMode) __);
+}
+
+
+/// Adds pattern-matching-related methods to [WebMode].
+extension WebModePatterns on WebMode {
+/// A variant of `map` that fallback to returning `orElse`.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case _:
+/// return orElse();
+/// }
+/// ```
+
+@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( WebMode_Disabled value)? disabled,TResult Function( WebMode_Download value)? download,TResult Function( WebMode_Upload value)? upload,required TResult orElse(),}){
+final _that = this;
+switch (_that) {
+case WebMode_Disabled() when disabled != null:
+return disabled(_that);case WebMode_Download() when download != null:
+return download(_that);case WebMode_Upload() when upload != null:
+return upload(_that);case _:
+ return orElse();
+
+}
+}
+/// A `switch`-like method, using callbacks.
+///
+/// Callbacks receives the raw object, upcasted.
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case final Subclass2 value:
+/// return ...;
+/// }
+/// ```
+
+@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( WebMode_Disabled value) disabled,required TResult Function( WebMode_Download value) download,required TResult Function( WebMode_Upload value) upload,}){
+final _that = this;
+switch (_that) {
+case WebMode_Disabled():
+return disabled(_that);case WebMode_Download():
+return download(_that);case WebMode_Upload():
+return upload(_that);}
+}
+/// A variant of `map` that fallback to returning `null`.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case _:
+/// return null;
+/// }
+/// ```
+
+@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( WebMode_Disabled value)? disabled,TResult? Function( WebMode_Download value)? download,TResult? Function( WebMode_Upload value)? upload,}){
+final _that = this;
+switch (_that) {
+case WebMode_Disabled() when disabled != null:
+return disabled(_that);case WebMode_Download() when download != null:
+return download(_that);case WebMode_Upload() when upload != null:
+return upload(_that);case _:
+ return null;
+
+}
+}
+/// A variant of `when` that fallback to an `orElse` callback.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case _:
+/// return orElse();
+/// }
+/// ```
+
+@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? disabled,TResult Function( Map<String, FileDto> files, String? pin)? download,TResult Function()? upload,required TResult orElse(),}) {final _that = this;
+switch (_that) {
+case WebMode_Disabled() when disabled != null:
+return disabled();case WebMode_Download() when download != null:
+return download(_that.files,_that.pin);case WebMode_Upload() when upload != null:
+return upload();case _:
+ return orElse();
+
+}
+}
+/// A `switch`-like method, using callbacks.
+///
+/// As opposed to `map`, this offers destructuring.
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case Subclass2(:final field2):
+/// return ...;
+/// }
+/// ```
+
+@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() disabled,required TResult Function( Map<String, FileDto> files, String? pin) download,required TResult Function() upload,}) {final _that = this;
+switch (_that) {
+case WebMode_Disabled():
+return disabled();case WebMode_Download():
+return download(_that.files,_that.pin);case WebMode_Upload():
+return upload();}
+}
+/// A variant of `when` that fallback to returning `null`
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case _:
+/// return null;
+/// }
+/// ```
+
+@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function()? disabled,TResult? Function( Map<String, FileDto> files, String? pin)? download,TResult? Function()? upload,}) {final _that = this;
+switch (_that) {
+case WebMode_Disabled() when disabled != null:
+return disabled();case WebMode_Download() when download != null:
+return download(_that.files,_that.pin);case WebMode_Upload() when upload != null:
+return upload();case _:
+ return null;
+
+}
+}
+
+}
+
+/// @nodoc
+
+
+class WebMode_Disabled extends WebMode {
+ const WebMode_Disabled(): super._();
+
+
+
+
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is WebMode_Disabled);
+}
+
+
+@override
+int get hashCode => runtimeType.hashCode;
+
+@override
+String toString() {
+ return 'WebMode.disabled()';
+}
+
+
+}
+
+
+
+
+/// @nodoc
+
+
+class WebMode_Download extends WebMode {
+ const WebMode_Download({required final Map<String, FileDto> files, this.pin}): _files = files,super._();
+
+
+/// The metadata of the files offered for download, mapped by file ID.
+/// The content is requested per download via [RsServerEvent::WebFileDownload].
+ final Map<String, FileDto> _files;
+/// The metadata of the files offered for download, mapped by file ID.
+/// The content is requested per download via [RsServerEvent::WebFileDownload].
+ Map<String, FileDto> get files {
+ if (_files is EqualUnmodifiableMapView) return _files;
+ // ignore: implicit_dynamic_type
+ return EqualUnmodifiableMapView(_files);
+}
+
+/// Optional PIN that web clients must provide via the `pin` query parameter.
+ final String? pin;
+
+/// Create a copy of WebMode
+/// with the given fields replaced by the non-null parameter values.
+@JsonKey(includeFromJson: false, includeToJson: false)
+@pragma('vm:prefer-inline')
+$WebMode_DownloadCopyWith<WebMode_Download> get copyWith => _$WebMode_DownloadCopyWithImpl<WebMode_Download>(this, _$identity);
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is WebMode_Download&&const DeepCollectionEquality().equals(other._files, _files)&&(identical(other.pin, pin) || other.pin == pin));
+}
+
+
+@override
+int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_files),pin);
+
+@override
+String toString() {
+ return 'WebMode.download(files: $files, pin: $pin)';
+}
+
+
+}
+
+/// @nodoc
+abstract mixin class $WebMode_DownloadCopyWith<$Res> implements $WebModeCopyWith<$Res> {
+ factory $WebMode_DownloadCopyWith(WebMode_Download value, $Res Function(WebMode_Download) _then) = _$WebMode_DownloadCopyWithImpl;
+@useResult
+$Res call({
+ Map<String, FileDto> files, String? pin
+});
+
+
+
+
+}
+/// @nodoc
+class _$WebMode_DownloadCopyWithImpl<$Res>
+ implements $WebMode_DownloadCopyWith<$Res> {
+ _$WebMode_DownloadCopyWithImpl(this._self, this._then);
+
+ final WebMode_Download _self;
+ final $Res Function(WebMode_Download) _then;
+
+/// Create a copy of WebMode
+/// with the given fields replaced by the non-null parameter values.
+@pragma('vm:prefer-inline') $Res call({Object? files = null,Object? pin = freezed,}) {
+ return _then(WebMode_Download(
+files: null == files ? _self._files : files // ignore: cast_nullable_to_non_nullable
+as Map<String, FileDto>,pin: freezed == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
+as String?,
+ ));
+}
+
+
+}
+
+/// @nodoc
+
+
+class WebMode_Upload extends WebMode {
+ const WebMode_Upload(): super._();
+
+
+
+
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is WebMode_Upload);
+}
+
+
+@override
+int get hashCode => runtimeType.hashCode;
+
+@override
+String toString() {
+ return 'WebMode.upload()';
+}
+
+
+}
+
+
+
+
// dart format on
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.dart b/packages/localsend_isolates/lib/rust/frb_generated.dart
index e9e84937..d30249bf 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.dart
@@ -310,7 +310,7 @@ abstract class RustLibApi extends BaseApi {
required String fingerprint,
String? pin,
required bool verifyChecksums,
- WebParams? web,
+ required WebParams web,
String? showToken,
});
@@ -2107,7 +2107,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
required String fingerprint,
String? pin,
required bool verifyChecksums,
- WebParams? web,
+ required WebParams web,
String? showToken,
}) {
return handler.executeNormal(
@@ -2123,7 +2123,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(fingerprint, serializer);
sse_encode_opt_String(pin, serializer);
sse_encode_bool(verifyChecksums, serializer);
- sse_encode_opt_box_autoadd_web_params(web, serializer);
+ sse_encode_box_autoadd_web_params(web, serializer);
sse_encode_opt_String(showToken, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 57, port: port_);
},
@@ -2698,24 +2698,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw as int;
}
- @protected
- WebPages dco_decode_box_autoadd_web_pages(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- return dco_decode_web_pages(raw);
- }
-
@protected
WebParams dco_decode_box_autoadd_web_params(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return dco_decode_web_params(raw);
}
- @protected
- WebSendParams dco_decode_box_autoadd_web_send_params(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- return dco_decode_web_send_params(raw);
- }
-
@protected
WsServerSdpMessage dco_decode_box_autoadd_ws_server_sdp_message(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -2953,24 +2941,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw == null ? null : dco_decode_box_autoadd_u_32(raw);
}
- @protected
- WebPages? dco_decode_opt_box_autoadd_web_pages(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- return raw == null ? null : dco_decode_box_autoadd_web_pages(raw);
- }
-
- @protected
- WebParams? dco_decode_opt_box_autoadd_web_params(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- return raw == null ? null : dco_decode_box_autoadd_web_params(raw);
- }
-
- @protected
- WebSendParams? dco_decode_opt_box_autoadd_web_send_params(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- return raw == null ? null : dco_decode_box_autoadd_web_send_params(raw);
- }
-
@protected
List<String>? dco_decode_opt_list_String(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -3468,6 +3438,24 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
}
+ @protected
+ WebMode dco_decode_web_mode(dynamic raw) {
+ // Codec=Dco (DartCObject based), see doc to use other codecs
+ switch (raw[0]) {
+ case 0:
+ return WebMode_Disabled();
+ case 1:
+ return WebMode_Download(
+ files: dco_decode_Map_String_file_dto_None(raw[1]),
+ pin: dco_decode_opt_String(raw[2]),
+ );
+ case 2:
+ return WebMode_Upload();
+ default:
+ throw Exception('unreachable');
+ }
+ }
+
@protected
WebPages dco_decode_web_pages(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -3484,23 +3472,11 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
WebParams dco_decode_web_params(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
- if (arr.length != 4) throw Exception('unexpected arr length: expect 4 but see ${arr.length}');
+ if (arr.length != 3) throw Exception('unexpected arr length: expect 3 but see ${arr.length}');
return WebParams(
- send: dco_decode_opt_box_autoadd_web_send_params(arr[0]),
- upload: dco_decode_bool(arr[1]),
- i18N: dco_decode_web_i_18_n(arr[2]),
- pages: dco_decode_opt_box_autoadd_web_pages(arr[3]),
- );
- }
-
- @protected
- WebSendParams dco_decode_web_send_params(dynamic raw) {
- // Codec=Dco (DartCObject based), see doc to use other codecs
- final arr = raw as List<dynamic>;
- if (arr.length != 2) throw Exception('unexpected arr length: expect 2 but see ${arr.length}');
- return WebSendParams(
- files: dco_decode_Map_String_file_dto_None(arr[0]),
- pin: dco_decode_opt_String(arr[1]),
+ mode: dco_decode_web_mode(arr[0]),
+ i18N: dco_decode_web_i_18_n(arr[1]),
+ pages: dco_decode_web_pages(arr[2]),
);
}
@@ -4011,24 +3987,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return (sse_decode_u_32(deserializer));
}
- @protected
- WebPages sse_decode_box_autoadd_web_pages(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- return (sse_decode_web_pages(deserializer));
- }
-
@protected
WebParams sse_decode_box_autoadd_web_params(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
return (sse_decode_web_params(deserializer));
}
- @protected
- WebSendParams sse_decode_box_autoadd_web_send_params(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- return (sse_decode_web_send_params(deserializer));
- }
-
@protected
WsServerSdpMessage sse_decode_box_autoadd_ws_server_sdp_message(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4353,39 +4317,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
- @protected
- WebPages? sse_decode_opt_box_autoadd_web_pages(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- if (sse_decode_bool(deserializer)) {
- return (sse_decode_box_autoadd_web_pages(deserializer));
- } else {
- return null;
- }
- }
-
- @protected
- WebParams? sse_decode_opt_box_autoadd_web_params(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- if (sse_decode_bool(deserializer)) {
- return (sse_decode_box_autoadd_web_params(deserializer));
- } else {
- return null;
- }
- }
-
- @protected
- WebSendParams? sse_decode_opt_box_autoadd_web_send_params(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- if (sse_decode_bool(deserializer)) {
- return (sse_decode_box_autoadd_web_send_params(deserializer));
- } else {
- return null;
- }
- }
-
@protected
List<String>? sse_decode_opt_list_String(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4876,6 +4807,25 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
}
+ @protected
+ WebMode sse_decode_web_mode(SseDeserializer deserializer) {
+ // Codec=Sse (Serialization based), see doc to use other codecs
+
+ var tag_ = sse_decode_i_32(deserializer);
+ switch (tag_) {
+ case 0:
+ return WebMode_Disabled();
+ case 1:
+ var var_files = sse_decode_Map_String_file_dto_None(deserializer);
+ var var_pin = sse_decode_opt_String(deserializer);
+ return WebMode_Download(files: var_files, pin: var_pin);
+ case 2:
+ return WebMode_Upload();
+ default:
+ throw UnimplementedError('');
+ }
+ }
+
@protected
WebPages sse_decode_web_pages(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4888,19 +4838,10 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
@protected
WebParams sse_decode_web_params(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
- var var_send = sse_decode_opt_box_autoadd_web_send_params(deserializer);
- var var_upload = sse_decode_bool(deserializer);
+ var var_mode = sse_decode_web_mode(deserializer);
var var_i18N = sse_decode_web_i_18_n(deserializer);
- var var_pages = sse_decode_opt_box_autoadd_web_pages(deserializer);
- return WebParams(send: var_send, upload: var_upload, i18N: var_i18N, pages: var_pages);
- }
-
- @protected
- WebSendParams sse_decode_web_send_params(SseDeserializer deserializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- var var_files = sse_decode_Map_String_file_dto_None(deserializer);
- var var_pin = sse_decode_opt_String(deserializer);
- return WebSendParams(files: var_files, pin: var_pin);
+ var var_pages = sse_decode_web_pages(deserializer);
+ return WebParams(mode: var_mode, i18N: var_i18N, pages: var_pages);
}
@protected
@@ -5529,24 +5470,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_32(self, serializer);
}
- @protected
- void sse_encode_box_autoadd_web_pages(WebPages self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- sse_encode_web_pages(self, serializer);
- }
-
@protected
void sse_encode_box_autoadd_web_params(WebParams self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_web_params(self, serializer);
}
- @protected
- void sse_encode_box_autoadd_web_send_params(WebSendParams self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- sse_encode_web_send_params(self, serializer);
- }
-
@protected
void sse_encode_box_autoadd_ws_server_sdp_message(WsServerSdpMessage self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -5823,36 +5752,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
- @protected
- void sse_encode_opt_box_autoadd_web_pages(WebPages? self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- sse_encode_bool(self != null, serializer);
- if (self != null) {
- sse_encode_box_autoadd_web_pages(self, serializer);
- }
- }
-
- @protected
- void sse_encode_opt_box_autoadd_web_params(WebParams? self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- sse_encode_bool(self != null, serializer);
- if (self != null) {
- sse_encode_box_autoadd_web_params(self, serializer);
- }
- }
-
- @protected
- void sse_encode_opt_box_autoadd_web_send_params(WebSendParams? self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
-
- sse_encode_bool(self != null, serializer);
- if (self != null) {
- sse_encode_box_autoadd_web_send_params(self, serializer);
- }
- }
-
@protected
void sse_encode_opt_list_String(List<String>? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -6244,6 +6143,21 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(self.dropHint, serializer);
}
+ @protected
+ void sse_encode_web_mode(WebMode self, SseSerializer serializer) {
+ // Codec=Sse (Serialization based), see doc to use other codecs
+ switch (self) {
+ case WebMode_Disabled():
+ sse_encode_i_32(0, serializer);
+ case WebMode_Download(files: final files, pin: final pin):
+ sse_encode_i_32(1, serializer);
+ sse_encode_Map_String_file_dto_None(files, serializer);
+ sse_encode_opt_String(pin, serializer);
+ case WebMode_Upload():
+ sse_encode_i_32(2, serializer);
+ }
+ }
+
@protected
void sse_encode_web_pages(WebPages self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -6255,17 +6169,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
@protected
void sse_encode_web_params(WebParams self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
- sse_encode_opt_box_autoadd_web_send_params(self.send, serializer);
- sse_encode_bool(self.upload, serializer);
+ sse_encode_web_mode(self.mode, serializer);
sse_encode_web_i_18_n(self.i18N, serializer);
- sse_encode_opt_box_autoadd_web_pages(self.pages, serializer);
- }
-
- @protected
- void sse_encode_web_send_params(WebSendParams self, SseSerializer serializer) {
- // Codec=Sse (Serialization based), see doc to use other codecs
- sse_encode_Map_String_file_dto_None(self.files, serializer);
- sse_encode_opt_String(self.pin, serializer);
+ sse_encode_web_pages(self.pages, serializer);
}
@protected
@@ -6648,7 +6554,7 @@ class RsHttpServerImpl extends RustOpaque implements RsHttpServer {
/// Emits server events until the server is stopped.
/// Can only be listened to once.
///
- /// The v2 protocol, the web send (download API), and the internal endpoint
+ /// The v2 protocol, the web download (download API), and the internal endpoint
/// events are all emitted on the same stream.
///
/// Also returns when the Dart side of the stream is gone (e.g. after a
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.io.dart b/packages/localsend_isolates/lib/rust/frb_generated.io.dart
index c05f9b87..d0835297 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.io.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.io.dart
@@ -283,15 +283,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int dco_decode_box_autoadd_u_32(dynamic raw);
- @protected
- WebPages dco_decode_box_autoadd_web_pages(dynamic raw);
-
@protected
WebParams dco_decode_box_autoadd_web_params(dynamic raw);
- @protected
- WebSendParams dco_decode_box_autoadd_web_send_params(dynamic raw);
-
@protected
WsServerSdpMessage dco_decode_box_autoadd_ws_server_sdp_message(dynamic raw);
@@ -389,15 +383,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int? dco_decode_opt_box_autoadd_u_32(dynamic raw);
- @protected
- WebPages? dco_decode_opt_box_autoadd_web_pages(dynamic raw);
-
- @protected
- WebParams? dco_decode_opt_box_autoadd_web_params(dynamic raw);
-
- @protected
- WebSendParams? dco_decode_opt_box_autoadd_web_send_params(dynamic raw);
-
@protected
List<String>? dco_decode_opt_list_String(dynamic raw);
@@ -510,13 +495,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
WebI18n dco_decode_web_i_18_n(dynamic raw);
@protected
- WebPages dco_decode_web_pages(dynamic raw);
+ WebMode dco_decode_web_mode(dynamic raw);
@protected
- WebParams dco_decode_web_params(dynamic raw);
+ WebPages dco_decode_web_pages(dynamic raw);
@protected
- WebSendParams dco_decode_web_send_params(dynamic raw);
+ WebParams dco_decode_web_params(dynamic raw);
@protected
WsServerMessage dco_decode_ws_server_message(dynamic raw);
@@ -762,15 +747,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int sse_decode_box_autoadd_u_32(SseDeserializer deserializer);
- @protected
- WebPages sse_decode_box_autoadd_web_pages(SseDeserializer deserializer);
-
@protected
WebParams sse_decode_box_autoadd_web_params(SseDeserializer deserializer);
- @protected
- WebSendParams sse_decode_box_autoadd_web_send_params(SseDeserializer deserializer);
-
@protected
WsServerSdpMessage sse_decode_box_autoadd_ws_server_sdp_message(SseDeserializer deserializer);
@@ -870,15 +849,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer);
- @protected
- WebPages? sse_decode_opt_box_autoadd_web_pages(SseDeserializer deserializer);
-
- @protected
- WebParams? sse_decode_opt_box_autoadd_web_params(SseDeserializer deserializer);
-
- @protected
- WebSendParams? sse_decode_opt_box_autoadd_web_send_params(SseDeserializer deserializer);
-
@protected
List<String>? sse_decode_opt_list_String(SseDeserializer deserializer);
@@ -991,13 +961,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
WebI18n sse_decode_web_i_18_n(SseDeserializer deserializer);
@protected
- WebPages sse_decode_web_pages(SseDeserializer deserializer);
+ WebMode sse_decode_web_mode(SseDeserializer deserializer);
@protected
- WebParams sse_decode_web_params(SseDeserializer deserializer);
+ WebPages sse_decode_web_pages(SseDeserializer deserializer);
@protected
- WebSendParams sse_decode_web_send_params(SseDeserializer deserializer);
+ WebParams sse_decode_web_params(SseDeserializer deserializer);
@protected
WsServerMessage sse_decode_ws_server_message(SseDeserializer deserializer);
@@ -1288,15 +1258,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer);
- @protected
- void sse_encode_box_autoadd_web_pages(WebPages self, SseSerializer serializer);
-
@protected
void sse_encode_box_autoadd_web_params(WebParams self, SseSerializer serializer);
- @protected
- void sse_encode_box_autoadd_web_send_params(WebSendParams self, SseSerializer serializer);
-
@protected
void sse_encode_box_autoadd_ws_server_sdp_message(WsServerSdpMessage self, SseSerializer serializer);
@@ -1396,15 +1360,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer);
- @protected
- void sse_encode_opt_box_autoadd_web_pages(WebPages? self, SseSerializer serializer);
-
- @protected
- void sse_encode_opt_box_autoadd_web_params(WebParams? self, SseSerializer serializer);
-
- @protected
- void sse_encode_opt_box_autoadd_web_send_params(WebSendParams? self, SseSerializer serializer);
-
@protected
void sse_encode_opt_list_String(List<String>? self, SseSerializer serializer);
@@ -1518,13 +1473,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
void sse_encode_web_i_18_n(WebI18n self, SseSerializer serializer);
@protected
- void sse_encode_web_pages(WebPages self, SseSerializer serializer);
+ void sse_encode_web_mode(WebMode self, SseSerializer serializer);
@protected
- void sse_encode_web_params(WebParams self, SseSerializer serializer);
+ void sse_encode_web_pages(WebPages self, SseSerializer serializer);
@protected
- void sse_encode_web_send_params(WebSendParams self, SseSerializer serializer);
+ void sse_encode_web_params(WebParams self, SseSerializer serializer);
@protected
void sse_encode_ws_server_message(WsServerMessage self, SseSerializer serializer);
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.web.dart b/packages/localsend_isolates/lib/rust/frb_generated.web.dart
index 8afe0d8b..d281d9e1 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.web.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.web.dart
@@ -285,15 +285,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int dco_decode_box_autoadd_u_32(dynamic raw);
- @protected
- WebPages dco_decode_box_autoadd_web_pages(dynamic raw);
-
@protected
WebParams dco_decode_box_autoadd_web_params(dynamic raw);
- @protected
- WebSendParams dco_decode_box_autoadd_web_send_params(dynamic raw);
-
@protected
WsServerSdpMessage dco_decode_box_autoadd_ws_server_sdp_message(dynamic raw);
@@ -391,15 +385,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int? dco_decode_opt_box_autoadd_u_32(dynamic raw);
- @protected
- WebPages? dco_decode_opt_box_autoadd_web_pages(dynamic raw);
-
- @protected
- WebParams? dco_decode_opt_box_autoadd_web_params(dynamic raw);
-
- @protected
- WebSendParams? dco_decode_opt_box_autoadd_web_send_params(dynamic raw);
-
@protected
List<String>? dco_decode_opt_list_String(dynamic raw);
@@ -512,13 +497,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
WebI18n dco_decode_web_i_18_n(dynamic raw);
@protected
- WebPages dco_decode_web_pages(dynamic raw);
+ WebMode dco_decode_web_mode(dynamic raw);
@protected
- WebParams dco_decode_web_params(dynamic raw);
+ WebPages dco_decode_web_pages(dynamic raw);
@protected
- WebSendParams dco_decode_web_send_params(dynamic raw);
+ WebParams dco_decode_web_params(dynamic raw);
@protected
WsServerMessage dco_decode_ws_server_message(dynamic raw);
@@ -764,15 +749,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int sse_decode_box_autoadd_u_32(SseDeserializer deserializer);
- @protected
- WebPages sse_decode_box_autoadd_web_pages(SseDeserializer deserializer);
-
@protected
WebParams sse_decode_box_autoadd_web_params(SseDeserializer deserializer);
- @protected
- WebSendParams sse_decode_box_autoadd_web_send_params(SseDeserializer deserializer);
-
@protected
WsServerSdpMessage sse_decode_box_autoadd_ws_server_sdp_message(SseDeserializer deserializer);
@@ -872,15 +851,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer);
- @protected
- WebPages? sse_decode_opt_box_autoadd_web_pages(SseDeserializer deserializer);
-
- @protected
- WebParams? sse_decode_opt_box_autoadd_web_params(SseDeserializer deserializer);
-
- @protected
- WebSendParams? sse_decode_opt_box_autoadd_web_send_params(SseDeserializer deserializer);
-
@protected
List<String>? sse_decode_opt_list_String(SseDeserializer deserializer);
@@ -993,13 +963,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
WebI18n sse_decode_web_i_18_n(SseDeserializer deserializer);
@protected
- WebPages sse_decode_web_pages(SseDeserializer deserializer);
+ WebMode sse_decode_web_mode(SseDeserializer deserializer);
@protected
- WebParams sse_decode_web_params(SseDeserializer deserializer);
+ WebPages sse_decode_web_pages(SseDeserializer deserializer);
@protected
- WebSendParams sse_decode_web_send_params(SseDeserializer deserializer);
+ WebParams sse_decode_web_params(SseDeserializer deserializer);
@protected
WsServerMessage sse_decode_ws_server_message(SseDeserializer deserializer);
@@ -1290,15 +1260,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer);
- @protected
- void sse_encode_box_autoadd_web_pages(WebPages self, SseSerializer serializer);
-
@protected
void sse_encode_box_autoadd_web_params(WebParams self, SseSerializer serializer);
- @protected
- void sse_encode_box_autoadd_web_send_params(WebSendParams self, SseSerializer serializer);
-
@protected
void sse_encode_box_autoadd_ws_server_sdp_message(WsServerSdpMessage self, SseSerializer serializer);
@@ -1398,15 +1362,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer);
- @protected
- void sse_encode_opt_box_autoadd_web_pages(WebPages? self, SseSerializer serializer);
-
- @protected
- void sse_encode_opt_box_autoadd_web_params(WebParams? self, SseSerializer serializer);
-
- @protected
- void sse_encode_opt_box_autoadd_web_send_params(WebSendParams? self, SseSerializer serializer);
-
@protected
void sse_encode_opt_list_String(List<String>? self, SseSerializer serializer);
@@ -1520,13 +1475,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
void sse_encode_web_i_18_n(WebI18n self, SseSerializer serializer);
@protected
- void sse_encode_web_pages(WebPages self, SseSerializer serializer);
+ void sse_encode_web_mode(WebMode self, SseSerializer serializer);
@protected
- void sse_encode_web_params(WebParams self, SseSerializer serializer);
+ void sse_encode_web_pages(WebPages self, SseSerializer serializer);
@protected
- void sse_encode_web_send_params(WebSendParams self, SseSerializer serializer);
+ void sse_encode_web_params(WebParams self, SseSerializer serializer);
@protected
void sse_encode_ws_server_message(WsServerMessage self, SseSerializer serializer);
diff --git a/packages/localsend_isolates/lib/src/isolate/child/server_isolate.dart b/packages/localsend_isolates/lib/src/isolate/child/server_isolate.dart
index efa29084..e4bc059e 100644
--- a/packages/localsend_isolates/lib/src/isolate/child/server_isolate.dart
+++ b/packages/localsend_isolates/lib/src/isolate/child/server_isolate.dart
@@ -34,9 +34,9 @@ class HttpServerStartTask implements BaseHttpServerTask {
/// verified after receiving.
final bool verifyChecksums;
- /// Serves the web pages: the download page (web send) and/or the upload page.
- /// `null` disables the web pages.
- final WebParams? web;
+ /// Configures the pages served to browsers: the download page (web download),
+ /// the upload page, or the 403 page when web share is disabled.
+ final WebParams web;
/// Enables the internal `show` endpoint, guarded by this token, that lets another
/// application instance request this one to show itself. `null` disables it.
diff --git a/packages/localsend_isolates/lib/src/isolate/parent/actions.dart b/packages/localsend_isolates/lib/src/isolate/parent/actions.dart
index 641d369c..2a97fc73 100644
--- a/packages/localsend_isolates/lib/src/isolate/parent/actions.dart
+++ b/packages/localsend_isolates/lib/src/isolate/parent/actions.dart
@@ -305,9 +305,9 @@ class IsolateHttpServerStartAction extends ReduxActionWithResult<IsolateControll
/// verified after receiving.
final bool verifyChecksums;
- /// Serves the web pages: the download page (web send) and/or the upload page.
- /// `null` disables the web pages.
- final WebParams? web;
+ /// Configures the pages served to browsers: the download page (web download),
+ /// the upload page, or the 403 page when web share is disabled.
+ final WebParams web;
/// Enables the internal `show` endpoint, guarded by this token, that lets another
/// application instance request this one to show itself. `null` disables it.
diff --git a/packages/localsend_isolates/lib/src/task/server/http_server.dart b/packages/localsend_isolates/lib/src/task/server/http_server.dart
index e0cdbf9a..9ad4fc52 100644
--- a/packages/localsend_isolates/lib/src/task/server/http_server.dart
+++ b/packages/localsend_isolates/lib/src/task/server/http_server.dart
@@ -23,7 +23,7 @@ class HttpServerService {
required String fingerprint,
required String? pin,
required bool verifyChecksums,
- required WebParams? web,
+ required WebParams web,
required String? showToken,
}) async {
if (_server != null) {
diff --git a/packages/localsend_isolates/rust/src/api/server.rs b/packages/localsend_isolates/rust/src/api/server.rs
index 77d5ea5e..aa165615 100644
--- a/packages/localsend_isolates/rust/src/api/server.rs
+++ b/packages/localsend_isolates/rust/src/api/server.rs
@@ -7,8 +7,10 @@ use localsend::http::server::common::save::FileUploadTarget;
use localsend::http::server::internal::{InternalConfig, InternalEvent};
pub use localsend::http::server::v2::SessionEndReasonV2;
use localsend::http::server::v2::{PrepareUploadDecisionV2, ServerEventV2};
+use localsend::http::server::web::{
+ WebConfig, WebMode as CoreWebMode, WebDownloadConfig, WebDownloadEvent,
+};
pub use localsend::http::server::web::{WebI18n, WebPages};
-use localsend::http::server::web::{WebConfig, WebSendConfig, WebSendEvent};
use localsend::http::state::ClientInfo;
use localsend::model::discovery::DeviceType;
use localsend::model::discovery::ProtocolType;
@@ -112,7 +114,7 @@ pub struct RsHttpServer {
event_rx: Mutex<Option<mpsc::Receiver<ServerEventV2>>>,
pending_decision: Mutex<Option<(String, oneshot::Sender<PrepareUploadDecisionV2>)>>,
pending_uploads: Mutex<HashMap<(String, String), oneshot::Sender<FileUploadTarget>>>,
- web_event_rx: Mutex<Option<mpsc::Receiver<WebSendEvent>>>,
+ web_event_rx: Mutex<Option<mpsc::Receiver<WebDownloadEvent>>>,
pending_download_decisions: Mutex<HashMap<String, oneshot::Sender<bool>>>,
pending_downloads: Mutex<HashMap<(String, String), oneshot::Sender<FileContent>>>,
internal_event_rx: Mutex<Option<mpsc::Receiver<InternalEvent>>>,
@@ -143,45 +145,54 @@ impl ServerInstance {
/// binding again.
static RUNNING_SERVER: Mutex<Option<Arc<ServerInstance>>> = Mutex::const_new(None);
-/// Configuration for the web pages served to browsers. When omitted, the web
-/// pages respond with 403 and only the v2 endpoints run.
+/// Configuration for the pages served to browsers. Always part of the server
+/// configuration: even with web share disabled ([WebMode::Disabled]), the
+/// server serves the 403 page at `/`.
pub struct WebParams {
- /// Enables web send (the download page): files offered for download by web
- /// browsers. `null` disables the download page and the download API.
- pub send: Option<WebSendParams>,
-
- /// Serves the upload page so web browsers can upload files via the v2
- /// `prepare-upload`/`upload` endpoints. Ignored when [WebParams::send] is
- /// set: the download page takes precedence at `/`.
- pub upload: bool,
+ /// What is served at `/` and which browser-facing API is active.
+ pub mode: WebMode,
/// Translations for the web pages, served via `/i18n.json`.
pub i18n: WebI18n,
/// Custom HTML pages replacing the embedded web pages.
- /// Pages left `null` (or the whole struct being `null`) are served from
- /// the assets embedded at compile time.
- pub pages: Option<WebPages>,
+ /// Pages left `null` are served from the assets embedded at compile time.
+ pub pages: WebPages,
}
-/// Configuration for web send: files offered for download by web browsers.
-///
-/// Web send can be enabled independently of the v2 protocol endpoints.
-pub struct WebSendParams {
- /// The metadata of the files offered for download, mapped by file ID.
- /// The content is requested per download via [RsServerEvent::WebFileDownload].
- pub files: HashMap<String, FileDto>,
-
- /// Optional PIN that web clients must provide via the `pin` query parameter.
- pub pin: Option<String>,
+/// What is served at `/` and which browser-facing API is active.
+/// The modes are mutually exclusive: only one page can live at `/`.
+pub enum WebMode {
+ /// No web share active: `/` serves the 403 page and client certificates
+ /// are mandatory under TLS, so the 403 page is effectively only reachable
+ /// when encryption is off.
+ Disabled,
+
+ /// Web download: the download page and the download API, offering files for
+ /// download by web browsers.
+ ///
+ /// Web download can be enabled independently of the v2 protocol endpoints.
+ Download {
+ /// The metadata of the files offered for download, mapped by file ID.
+ /// The content is requested per download via [RsServerEvent::WebFileDownload].
+ files: HashMap<String, FileDto>,
+
+ /// Optional PIN that web clients must provide via the `pin` query parameter.
+ pin: Option<String>,
+ },
+
+ /// The upload page: web browsers upload files via the v2
+ /// `prepare-upload`/`upload` endpoints.
+ Upload,
}
/// Starts the HTTP server on the given port (IPv4 and IPv6).
/// The server runs until [RsHttpServer::stop] is called.
///
-/// Passing [web] additionally serves the web pages: the download page when
-/// [WebParams::send] is set (so web browsers can download the offered files)
-/// or the upload page when [WebParams::upload] is enabled.
+/// [web] configures the pages served to browsers: [WebParams::mode] selects
+/// the download page ([WebMode::Download], so web browsers can download the
+/// offered files), the upload page ([WebMode::Upload]) or no web share at all
+/// ([WebMode::Disabled], serving the 403 page).
///
/// Passing [show_token] enables the internal `show` endpoint that lets another
/// application instance request this one to show itself (emitted as
@@ -198,7 +209,7 @@ pub async fn start_server(
fingerprint: String,
pin: Option<String>,
verify_checksums: bool,
- web: Option<WebParams>,
+ web: WebParams,
show_token: Option<String>,
) -> anyhow::Result<RsHttpServer> {
// Stop a server left over from before a hot restart (its Dart owner died
@@ -211,29 +222,23 @@ pub async fn start_server(
let (event_tx, event_rx) = mpsc::channel::<ServerEventV2>(16);
let (stop_tx, stop_rx) = oneshot::channel::<()>();
- let (web_config, web_event_rx) = match web {
- Some(web) => {
- let (send_config, web_event_rx) = match web.send {
- Some(send) => {
- let (web_event_tx, web_event_rx) = mpsc::channel::<WebSendEvent>(16);
- let config = WebSendConfig {
- files: send.files,
- pin: send.pin,
- event_tx: web_event_tx,
- };
- (Some(config), Some(web_event_rx))
- }
- None => (None, None),
- };
- let config = WebConfig {
- send: send_config,
- upload: web.upload,
- i18n: web.i18n,
- pages: web.pages.unwrap_or_default(),
- };
- (Some(config), web_event_rx)
+ let (web_mode, web_event_rx) = match web.mode {
+ WebMode::Disabled => (CoreWebMode::Disabled, None),
+ WebMode::Download { files, pin } => {
+ let (web_event_tx, web_event_rx) = mpsc::channel::<WebDownloadEvent>(16);
+ let mode = CoreWebMode::Download(WebDownloadConfig {
+ files,
+ pin,
+ event_tx: web_event_tx,
+ });
+ (mode, Some(web_event_rx))
}
- None => (None, None),
+ WebMode::Upload => (CoreWebMode::Upload, None),
+ };
+ let web_config = WebConfig {
+ mode: web_mode,
+ i18n: web.i18n,
+ pages: web.pages,
};
let (internal_config, internal_event_rx) = match show_token {
@@ -291,7 +296,7 @@ impl RsHttpServer {
/// Emits server events until the server is stopped.
/// Can only be listened to once.
///
- /// The v2 protocol, the web send (download API), and the internal endpoint
+ /// The v2 protocol, the web download (download API), and the internal endpoint
/// events are all emitted on the same stream.
///
/// Also returns when the Dart side of the stream is gone (e.g. after a
@@ -435,10 +440,10 @@ impl RsHttpServer {
async fn handle_web_event(
&self,
sink: &StreamSink<RsServerEvent>,
- event: WebSendEvent,
+ event: WebDownloadEvent,
) -> bool {
match event {
- WebSendEvent::PrepareDownload {
+ WebDownloadEvent::PrepareDownload {
ip,
session_id,
user_agent,
@@ -455,7 +460,7 @@ impl RsHttpServer {
})
.is_ok()
}
- WebSendEvent::FileDownload {
+ WebDownloadEvent::FileDownload {
session_id,
file_id,
file,
diff --git a/packages/localsend_isolates/rust/src/frb_generated.rs b/packages/localsend_isolates/rust/src/frb_generated.rs
index 20185f10..f311cd47 100644
--- a/packages/localsend_isolates/rust/src/frb_generated.rs
+++ b/packages/localsend_isolates/rust/src/frb_generated.rs
@@ -3303,7 +3303,7 @@ fn wire__crate__api__server__start_server_impl(
let api_fingerprint = <String>::sse_decode(&mut deserializer);
let api_pin = <Option<String>>::sse_decode(&mut deserializer);
let api_verify_checksums = <bool>::sse_decode(&mut deserializer);
- let api_web = <Option<crate::api::server::WebParams>>::sse_decode(&mut deserializer);
+ let api_web = <crate::api::server::WebParams>::sse_decode(&mut deserializer);
let api_show_token = <Option<String>>::sse_decode(&mut deserializer);
deserializer.end();
move |context| async move {
@@ -4368,41 +4368,6 @@ impl SseDecode for Option<u32> {
}
}
-impl SseDecode for Option<crate::api::server::WebPages> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
- if (<bool>::sse_decode(deserializer)) {
- return Some(<crate::api::server::WebPages>::sse_decode(deserializer));
- } else {
- return None;
- }
- }
-}
-
-impl SseDecode for Option<crate::api::server::WebParams> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
- if (<bool>::sse_decode(deserializer)) {
- return Some(<crate::api::server::WebParams>::sse_decode(deserializer));
- } else {
- return None;
- }
- }
-}
-
-impl SseDecode for Option<crate::api::server::WebSendParams> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
- if (<bool>::sse_decode(deserializer)) {
- return Some(<crate::api::server::WebSendParams>::sse_decode(
- deserializer,
- ));
- } else {
- return None;
- }
- }
-}
-
impl SseDecode for Option<Vec<String>> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
@@ -5038,6 +5003,35 @@ impl SseDecode for crate::api::server::WebI18n {
}
}
+impl SseDecode for crate::api::server::WebMode {
+ // Codec=Sse (Serialization based), see doc to use other codecs
+ fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
+ let mut tag_ = <i32>::sse_decode(deserializer);
+ match tag_ {
+ 0 => {
+ return crate::api::server::WebMode::Disabled;
+ }
+ 1 => {
+ let mut var_files =
+ <std::collections::HashMap<String, crate::api::model::FileDto>>::sse_decode(
+ deserializer,
+ );
+ let mut var_pin = <Option<String>>::sse_decode(deserializer);
+ return crate::api::server::WebMode::Download {
+ files: var_files,
+ pin: var_pin,
+ };
+ }
+ 2 => {
+ return crate::api::server::WebMode::Upload;
+ }
+ _ => {
+ unimplemented!("");
+ }
+ }
+ }
+}
+
impl SseDecode for crate::api::server::WebPages {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
@@ -5055,34 +5049,17 @@ impl SseDecode for crate::api::server::WebPages {
impl SseDecode for crate::api::server::WebParams {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
- let mut var_send = <Option<crate::api::server::WebSendParams>>::sse_decode(deserializer);
- let mut var_upload = <bool>::sse_decode(deserializer);
+ let mut var_mode = <crate::api::server::WebMode>::sse_decode(deserializer);
let mut var_i18N = <crate::api::server::WebI18n>::sse_decode(deserializer);
- let mut var_pages = <Option<crate::api::server::WebPages>>::sse_decode(deserializer);
+ let mut var_pages = <crate::api::server::WebPages>::sse_decode(deserializer);
return crate::api::server::WebParams {
- send: var_send,
- upload: var_upload,
+ mode: var_mode,
i18n: var_i18N,
pages: var_pages,
};
}
}
-impl SseDecode for crate::api::server::WebSendParams {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
- let mut var_files =
- <std::collections::HashMap<String, crate::api::model::FileDto>>::sse_decode(
- deserializer,
- );
- let mut var_pin = <Option<String>>::sse_decode(deserializer);
- return crate::api::server::WebSendParams {
- files: var_files,
- pin: var_pin,
- };
- }
-}
-
impl SseDecode for crate::api::webrtc::WsServerMessage {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
@@ -6481,6 +6458,32 @@ impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<crate::api::server::WebI18n>>
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
+impl flutter_rust_bridge::IntoDart for crate::api::server::WebMode {
+ fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
+ match self {
+ crate::api::server::WebMode::Disabled => [0.into_dart()].into_dart(),
+ crate::api::server::WebMode::Download { files, pin } => [
+ 1.into_dart(),
+ files.into_into_dart().into_dart(),
+ pin.into_into_dart().into_dart(),
+ ]
+ .into_dart(),
+ crate::api::server::WebMode::Upload => [2.into_dart()].into_dart(),
+ _ => {
+ unimplemented!("");
+ }
+ }
+ }
+}
+impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::api::server::WebMode {}
+impl flutter_rust_bridge::IntoIntoDart<crate::api::server::WebMode>
+ for crate::api::server::WebMode
+{
+ fn into_into_dart(self) -> crate::api::server::WebMode {
+ self
+ }
+}
+// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for FrbWrapper<crate::api::server::WebPages> {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
@@ -6506,8 +6509,7 @@ impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<crate::api::server::WebPages>>
impl flutter_rust_bridge::IntoDart for crate::api::server::WebParams {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
- self.send.into_into_dart().into_dart(),
- self.upload.into_into_dart().into_dart(),
+ self.mode.into_into_dart().into_dart(),
self.i18n.into_into_dart().into_dart(),
self.pages.into_into_dart().into_dart(),
]
@@ -6523,27 +6525,6 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::server::WebParams>
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
-impl flutter_rust_bridge::IntoDart for crate::api::server::WebSendParams {
- fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
- [
- self.files.into_into_dart().into_dart(),
- self.pin.into_into_dart().into_dart(),
- ]
- .into_dart()
- }
-}
-impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
- for crate::api::server::WebSendParams
-{
-}
-impl flutter_rust_bridge::IntoIntoDart<crate::api::server::WebSendParams>
- for crate::api::server::WebSendParams
-{
- fn into_into_dart(self) -> crate::api::server::WebSendParams {
- self
- }
-}
-// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for FrbWrapper<crate::api::webrtc::WsServerMessage> {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self.0 {
@@ -7295,36 +7276,6 @@ impl SseEncode for Option<u32> {
}
}
-impl SseEncode for Option<crate::api::server::WebPages> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
- <bool>::sse_encode(self.is_some(), serializer);
- if let Some(value) = self {
- <crate::api::server::WebPages>::sse_encode(value, serializer);
- }
- }
-}
-
-impl SseEncode for Option<crate::api::server::WebParams> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
- <bool>::sse_encode(self.is_some(), serializer);
- if let Some(value) = self {
- <crate::api::server::WebParams>::sse_encode(value, serializer);
- }
- }
-}
-
-impl SseEncode for Option<crate::api::server::WebSendParams> {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
- <bool>::sse_encode(self.is_some(), serializer);
- if let Some(value) = self {
- <crate::api::server::WebSendParams>::sse_encode(value, serializer);
- }
- }
-}
-
impl SseEncode for Option<Vec<String>> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
@@ -7827,6 +7778,30 @@ impl SseEncode for crate::api::server::WebI18n {
}
}
+impl SseEncode for crate::api::server::WebMode {
+ // Codec=Sse (Serialization based), see doc to use other codecs
+ fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
+ match self {
+ crate::api::server::WebMode::Disabled => {
+ <i32>::sse_encode(0, serializer);
+ }
+ crate::api::server::WebMode::Download { files, pin } => {
+ <i32>::sse_encode(1, serializer);
+ <std::collections::HashMap<String, crate::api::model::FileDto>>::sse_encode(
+ files, serializer,
+ );
+ <Option<String>>::sse_encode(pin, serializer);
+ }
+ crate::api::server::WebMode::Upload => {
+ <i32>::sse_encode(2, serializer);
+ }
+ _ => {
+ unimplemented!("");
+ }
+ }
+ }
+}
+
impl SseEncode for crate::api::server::WebPages {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
@@ -7839,20 +7814,9 @@ impl SseEncode for crate::api::server::WebPages {
impl SseEncode for crate::api::server::WebParams {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
- <Option<crate::api::server::WebSendParams>>::sse_encode(self.send, serializer);
- <bool>::sse_encode(self.upload, serializer);
+ <crate::api::server::WebMode>::sse_encode(self.mode, serializer);
<crate::api::server::WebI18n>::sse_encode(self.i18n, serializer);
- <Option<crate::api::server::WebPages>>::sse_encode(self.pages, serializer);
- }
-}
-
-impl SseEncode for crate::api::server::WebSendParams {
- // Codec=Sse (Serialization based), see doc to use other codecs
- fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
- <std::collections::HashMap<String, crate::api::model::FileDto>>::sse_encode(
- self.files, serializer,
- );
- <Option<String>>::sse_encode(self.pin, serializer);
+ <crate::api::server::WebPages>::sse_encode(self.pages, serializer);
}
}
diff --git a/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart b/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart
index 6bd14320..bedb8915 100644
--- a/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart
+++ b/packages/localsend_isolates/test/task/server/cancel_session_repro_test.dart
@@ -53,7 +53,23 @@ void main() {
fingerprint: 'RECEIVER-FINGERPRINT',
pin: null,
verifyChecksums: true,
- web: null,
+ web: const WebParams(
+ mode: WebMode.disabled(),
+ i18N: WebI18n(
+ waiting: '',
+ enterPin: '',
+ invalidPin: '',
+ tooManyAttempts: '',
+ rejected: '',
+ uploadRejected: '',
+ busy: '',
+ files: '',
+ fileName: '',
+ size: '',
+ dropHint: '',
+ ),
+ pages: WebPages(),
+ ),
showToken: null,
);