idle
This commit is contained in:
@@ -16,7 +16,9 @@ void configureDependencies(SessionBloc sessionBloc) {
|
||||
// Register repositories (HTTP-backed)
|
||||
final apiClient = ApiClient(sessionBloc);
|
||||
getIt.registerSingleton<AuthRepository>(HttpAuthRepository(apiClient));
|
||||
getIt.registerSingleton<FileRepository>(HttpFileRepository(FileService(apiClient)));
|
||||
getIt.registerSingleton<FileRepository>(
|
||||
HttpFileRepository(FileService(apiClient)),
|
||||
);
|
||||
|
||||
// Register services
|
||||
getIt.registerSingleton<AuthService>(AuthService(getIt<AuthRepository>()));
|
||||
|
||||
@@ -8,18 +8,21 @@ class HttpAuthRepository implements AuthRepository {
|
||||
|
||||
@override
|
||||
Future<User> login(String email, String password) async {
|
||||
final res = await _apiClient.post('/auth/password-login', data: {
|
||||
'username': email,
|
||||
'password': password,
|
||||
}, fromJson: (d) {
|
||||
final user = d['user'];
|
||||
return User(
|
||||
id: user['id'].toString(),
|
||||
username: user['username'] ?? user['email'],
|
||||
email: user['email'],
|
||||
createdAt: DateTime.parse(user['createdAt'] ?? DateTime.now().toIso8601String()),
|
||||
);
|
||||
});
|
||||
final res = await _apiClient.post(
|
||||
'/auth/password-login',
|
||||
data: {'username': email, 'password': password},
|
||||
fromJson: (d) {
|
||||
final user = d['user'];
|
||||
return User(
|
||||
id: user['id'].toString(),
|
||||
username: user['username'] ?? user['email'],
|
||||
email: user['email'],
|
||||
createdAt: DateTime.parse(
|
||||
user['createdAt'] ?? DateTime.now().toIso8601String(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -34,7 +37,9 @@ class HttpAuthRepository implements AuthRepository {
|
||||
id: user['id'].toString(),
|
||||
username: user['username'] ?? user['email'],
|
||||
email: user['email'],
|
||||
createdAt: DateTime.parse(user['createdAt'] ?? DateTime.now().toIso8601String()),
|
||||
createdAt: DateTime.parse(
|
||||
user['createdAt'] ?? DateTime.now().toIso8601String(),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
@@ -35,12 +35,20 @@ class HttpFileRepository implements FileRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> createFolder(String orgId, String parentPath, String folderName) async {
|
||||
Future<void> createFolder(
|
||||
String orgId,
|
||||
String parentPath,
|
||||
String folderName,
|
||||
) async {
|
||||
await _fileService.createFolder(orgId, parentPath, folderName);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> moveFile(String orgId, String sourcePath, String targetPath) async {
|
||||
Future<void> moveFile(
|
||||
String orgId,
|
||||
String sourcePath,
|
||||
String targetPath,
|
||||
) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -53,21 +61,33 @@ class HttpFileRepository implements FileRepository {
|
||||
Future<List<FileItem>> searchFiles(String orgId, String query) async {
|
||||
// Not yet parameterized on API side; fallback to client-side filter
|
||||
final files = await getFiles(orgId, '/');
|
||||
return files.where((f) => f.name.toLowerCase().contains(query.toLowerCase())).toList();
|
||||
return files
|
||||
.where((f) => f.name.toLowerCase().contains(query.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ViewerSession> requestViewerSession(String orgId, String fileId) async {
|
||||
Future<ViewerSession> requestViewerSession(
|
||||
String orgId,
|
||||
String fileId,
|
||||
) async {
|
||||
return await _fileService.requestViewerSession(orgId, fileId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<EditorSession> requestEditorSession(String orgId, String fileId) async {
|
||||
Future<EditorSession> requestEditorSession(
|
||||
String orgId,
|
||||
String fileId,
|
||||
) async {
|
||||
return await _fileService.requestEditorSession(orgId, fileId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveAnnotations(String orgId, String fileId, List<Annotation> annotations) async {
|
||||
Future<void> saveAnnotations(
|
||||
String orgId,
|
||||
String fileId,
|
||||
List<Annotation> annotations,
|
||||
) async {
|
||||
await _fileService.saveAnnotations(orgId, fileId, annotations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ class FileService {
|
||||
|
||||
Future<void> uploadFile(String orgId, FileItem file) async {
|
||||
// If bytes or localPath available, send multipart upload with field 'file'
|
||||
final Map<String, dynamic> fields = {
|
||||
'path': file.path,
|
||||
};
|
||||
final Map<String, dynamic> fields = {'path': file.path};
|
||||
FormData formData;
|
||||
if (file.bytes != null) {
|
||||
formData = FormData.fromMap({
|
||||
@@ -74,24 +72,44 @@ class FileService {
|
||||
await _apiClient.post('/user/files', data: data, fromJson: (d) => null);
|
||||
return;
|
||||
}
|
||||
await _apiClient.post('/orgs/$orgId/files', data: data, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/orgs/$orgId/files',
|
||||
data: data,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (orgId.isEmpty) {
|
||||
await _apiClient.post('/user/files', data: formData, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/user/files',
|
||||
data: formData,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await _apiClient.post('/orgs/$orgId/files', data: formData, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/orgs/$orgId/files',
|
||||
data: formData,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteFile(String orgId, String path) async {
|
||||
final data = {'path': path};
|
||||
if (orgId.isEmpty) {
|
||||
await _apiClient.post('/user/files/delete', data: data, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/user/files/delete',
|
||||
data: data,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await _apiClient.post('/orgs/$orgId/files/delete', data: data, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/orgs/$orgId/files/delete',
|
||||
data: data,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createFolder(
|
||||
@@ -99,7 +117,9 @@ class FileService {
|
||||
String parentPath,
|
||||
String folderName,
|
||||
) async {
|
||||
final path = parentPath.endsWith('/') ? '$parentPath$folderName' : '$parentPath/$folderName';
|
||||
final path = parentPath.endsWith('/')
|
||||
? '$parentPath$folderName'
|
||||
: '$parentPath/$folderName';
|
||||
final data = {
|
||||
'name': folderName,
|
||||
'path': path,
|
||||
@@ -110,7 +130,11 @@ class FileService {
|
||||
await _apiClient.post('/user/files', data: data, fromJson: (d) => null);
|
||||
return;
|
||||
}
|
||||
await _apiClient.post('/orgs/$orgId/files', data: data, fromJson: (d) => null);
|
||||
await _apiClient.post(
|
||||
'/orgs/$orgId/files',
|
||||
data: data,
|
||||
fromJson: (d) => null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> moveFile(
|
||||
|
||||
@@ -2,13 +2,13 @@ package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"go.b0esche.cloud/backend/internal/audit"
|
||||
"go.b0esche.cloud/backend/internal/auth"
|
||||
|
||||
Reference in New Issue
Block a user