mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
164 lines
4.7 KiB
Dart
164 lines
4.7 KiB
Dart
// This file is automatically generated, so please do not edit it.
|
|
// @generated by `flutter_rust_bridge`@ 2.12.0.
|
|
|
|
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
|
|
|
|
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
|
|
import 'package:localsend_app/rust/api/model.dart';
|
|
import 'package:localsend_app/rust/frb_generated.dart';
|
|
|
|
part 'server.freezed.dart';
|
|
|
|
// These functions are ignored because they are not marked as `pub`: `resolve_upload_target`
|
|
|
|
/// Starts the HTTP server on the given port (IPv4 and IPv6).
|
|
/// The server runs until [RsHttpServer::stop] is called.
|
|
///
|
|
/// Events are received by listening to [RsHttpServer::listen].
|
|
Future<RsHttpServer> startServer({
|
|
required int port,
|
|
TlsConfig? tls,
|
|
required String alias,
|
|
required String version,
|
|
String? deviceModel,
|
|
DeviceType? deviceType,
|
|
required String fingerprint,
|
|
String? pin,
|
|
}) => RustLib.instance.api.crateApiServerStartServer(
|
|
port: port,
|
|
tls: tls,
|
|
alias: alias,
|
|
version: version,
|
|
deviceModel: deviceModel,
|
|
deviceType: deviceType,
|
|
fingerprint: fingerprint,
|
|
pin: pin,
|
|
);
|
|
|
|
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<RsHttpServer>>
|
|
abstract class RsHttpServer implements RustOpaqueInterface {
|
|
/// Emits server events until the server is stopped.
|
|
/// Can only be listened to once.
|
|
Stream<RsServerEvent> listen();
|
|
|
|
/// Answers the pending [RsServerEvent::FileUpload] event with the target
|
|
/// the file should be saved to (either a path or a file descriptor)
|
|
/// and waits until the file has been received completely.
|
|
Future<void> respondFileUpload({required String sessionId, required String fileId, String? path, int? fileDescriptor});
|
|
|
|
/// Answers the pending [RsServerEvent::PrepareUpload] event.
|
|
///
|
|
/// Passing the accepted file IDs (a subset of the offered files) accepts the request.
|
|
/// Passing `None` declines the request.
|
|
Future<void> respondPrepareUpload({List<String>? acceptedFileIds});
|
|
|
|
/// Stops the server.
|
|
Future<void> stop();
|
|
}
|
|
|
|
enum ProtocolTypeV2 {
|
|
http,
|
|
https,
|
|
}
|
|
|
|
class RegisterDtoV2 {
|
|
final String alias;
|
|
final String version;
|
|
final String? deviceModel;
|
|
final DeviceType? deviceType;
|
|
final String fingerprint;
|
|
final int port;
|
|
final ProtocolTypeV2 protocol;
|
|
final bool download;
|
|
|
|
const RegisterDtoV2({
|
|
required this.alias,
|
|
required this.version,
|
|
this.deviceModel,
|
|
this.deviceType,
|
|
required this.fingerprint,
|
|
required this.port,
|
|
required this.protocol,
|
|
required this.download,
|
|
});
|
|
|
|
@override
|
|
int get hashCode =>
|
|
alias.hashCode ^
|
|
version.hashCode ^
|
|
deviceModel.hashCode ^
|
|
deviceType.hashCode ^
|
|
fingerprint.hashCode ^
|
|
port.hashCode ^
|
|
protocol.hashCode ^
|
|
download.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is RegisterDtoV2 &&
|
|
runtimeType == other.runtimeType &&
|
|
alias == other.alias &&
|
|
version == other.version &&
|
|
deviceModel == other.deviceModel &&
|
|
deviceType == other.deviceType &&
|
|
fingerprint == other.fingerprint &&
|
|
port == other.port &&
|
|
protocol == other.protocol &&
|
|
download == other.download;
|
|
}
|
|
|
|
@freezed
|
|
sealed class RsServerEvent with _$RsServerEvent {
|
|
const RsServerEvent._();
|
|
|
|
/// A device registered itself via `POST /api/localsend/v2/register`.
|
|
const factory RsServerEvent.register({
|
|
required String ip,
|
|
required RegisterDtoV2 info,
|
|
}) = RsServerEvent_Register;
|
|
|
|
/// A sender requests to upload files via `POST /api/localsend/v2/prepare-upload`.
|
|
const factory RsServerEvent.prepareUpload({
|
|
required String ip,
|
|
required RegisterDtoV2 info,
|
|
required Map<String, FileDto> files,
|
|
}) = RsServerEvent_PrepareUpload;
|
|
|
|
/// An accepted file is being uploaded via `POST /api/localsend/v2/upload`.
|
|
const factory RsServerEvent.fileUpload({
|
|
required String sessionId,
|
|
required String fileId,
|
|
required FileDto file,
|
|
}) = RsServerEvent_FileUpload;
|
|
|
|
/// An upload session ended.
|
|
const factory RsServerEvent.sessionEnd({
|
|
required String sessionId,
|
|
required SessionEndReasonV2 reason,
|
|
}) = RsServerEvent_SessionEnd;
|
|
}
|
|
|
|
enum SessionEndReasonV2 {
|
|
finished,
|
|
cancelled,
|
|
}
|
|
|
|
class TlsConfig {
|
|
final String cert;
|
|
final String privateKey;
|
|
|
|
const TlsConfig({
|
|
required this.cert,
|
|
required this.privateKey,
|
|
});
|
|
|
|
@override
|
|
int get hashCode => cert.hashCode ^ privateKey.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) || other is TlsConfig && runtimeType == other.runtimeType && cert == other.cert && privateKey == other.privateKey;
|
|
}
|