Fix: Refactor code for improved readability and consistency in document viewer and signup form

This commit is contained in:
Leon Bösche
2026-01-12 01:18:08 +01:00
parent 36db2daabd
commit ec25f06ea3
4 changed files with 59 additions and 67 deletions

View File

@@ -363,11 +363,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(Icons.error_outline, size: 64, color: Colors.red[400]),
Icons.error_outline,
size: 64,
color: Colors.red[400],
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Failed to load document', 'Failed to load document',
@@ -406,7 +402,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
final wopiSession = snapshot.data!; final wopiSession = snapshot.data!;
// Build Collabora Online viewer URL with WOPISrc // Build Collabora Online viewer URL with WOPISrc
final collaboraUrl = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=${Uri.encodeComponent(wopiSession.wopisrc)}'; final collaboraUrl =
'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=${Uri.encodeComponent(wopiSession.wopisrc)}';
// Use WebView to display Collabora Online // Use WebView to display Collabora Online
return _buildWebView(collaboraUrl); return _buildWebView(collaboraUrl);
@@ -427,13 +424,15 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
endpoint = '/user/files/${widget.fileId}/wopi-session'; endpoint = '/user/files/${widget.fileId}/wopi-session';
} }
final response = await http.post( final response = await http
Uri.parse('$baseUrl$endpoint'), .post(
headers: { Uri.parse('$baseUrl$endpoint'),
'Authorization': 'Bearer $token', headers: {
'Content-Type': 'application/json', 'Authorization': 'Bearer $token',
}, 'Content-Type': 'application/json',
).timeout(const Duration(seconds: 10)); },
)
.timeout(const Duration(seconds: 10));
if (response.statusCode == 200) { if (response.statusCode == 200) {
final json = jsonDecode(response.body) as Map<String, dynamic>; final json = jsonDecode(response.body) as Map<String, dynamic>;
@@ -442,7 +441,9 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
accessToken: json['access_token'] as String, accessToken: json['access_token'] as String,
); );
} else { } else {
throw Exception('Failed to create WOPI session: ${response.statusCode}'); throw Exception(
'Failed to create WOPI session: ${response.statusCode}',
);
} }
} catch (e) { } catch (e) {
throw Exception('Error creating WOPI session: $e'); throw Exception('Error creating WOPI session: $e');
@@ -459,7 +460,11 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const Icon(Icons.description, size: 64, color: AppTheme.accentColor), const Icon(
Icons.description,
size: 64,
color: AppTheme.accentColor,
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Collabora Online Viewer', 'Collabora Online Viewer',
@@ -476,7 +481,9 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
onPressed: () { onPressed: () {
// You can implement opening in browser or using webview here // You can implement opening in browser or using webview here
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Collabora viewer loading...')), const SnackBar(
content: Text('Collabora viewer loading...'),
),
); );
}, },
child: const Text('Open Document'), child: const Text('Open Document'),
@@ -500,10 +507,7 @@ class WOPISession {
final String wopisrc; final String wopisrc;
final String accessToken; final String accessToken;
WOPISession({ WOPISession({required this.wopisrc, required this.accessToken});
required this.wopisrc,
required this.accessToken,
});
factory WOPISession.fromJson(Map<String, dynamic> json) { factory WOPISession.fromJson(Map<String, dynamic> json) {
return WOPISession( return WOPISession(
@@ -799,11 +803,7 @@ class _DocumentViewerState extends State<DocumentViewer> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(Icons.description, size: 64, color: AppTheme.accentColor),
Icons.description,
size: 64,
color: AppTheme.accentColor,
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Office Document', 'Office Document',
@@ -816,24 +816,16 @@ class _DocumentViewerState extends State<DocumentViewer> {
const SizedBox(height: 8), const SizedBox(height: 8),
Text( Text(
'Collabora Online Viewer', 'Collabora Online Viewer',
style: TextStyle( style: TextStyle(color: AppTheme.secondaryText, fontSize: 14),
color: AppTheme.secondaryText,
fontSize: 14,
),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Opening document in Collabora...', 'Opening document in Collabora...',
style: TextStyle( style: TextStyle(color: AppTheme.secondaryText, fontSize: 12),
color: AppTheme.secondaryText,
fontSize: 12,
),
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
CircularProgressIndicator( CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>( valueColor: AlwaysStoppedAnimation<Color>(AppTheme.accentColor),
AppTheme.accentColor,
),
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
ElevatedButton.icon( ElevatedButton.icon(

View File

@@ -29,7 +29,6 @@ class _SignupFormState extends State<SignupForm> {
super.dispose(); super.dispose();
} }
String _generateRandomBase64(int bytes) { String _generateRandomBase64(int bytes) {
final random = Random(); final random = Random();
final values = List<int>.generate(bytes, (i) => random.nextInt(256)); final values = List<int>.generate(bytes, (i) => random.nextInt(256));

View File

@@ -674,4 +674,5 @@ func (db *DB) MarkChallengeUsed(ctx context.Context, challenge []byte) error {
`, challenge) `, challenge)
return err return err
} }
// UpdateFileSize updates the size and last_modified timestamp of a file // UpdateFileSize updates the size and last_modified timestamp of a file

View File

@@ -183,32 +183,32 @@ func wopiCheckFileInfoHandler(w http.ResponseWriter, r *http.Request, db *databa
// Build response // Build response
response := models.WOPICheckFileInfoResponse{ response := models.WOPICheckFileInfoResponse{
BaseFileName: file.Name, BaseFileName: file.Name,
Size: file.Size, Size: file.Size,
Version: file.ID.String(), Version: file.ID.String(),
OwnerId: ownerID, OwnerId: ownerID,
UserId: userID.String(), UserId: userID.String(),
UserFriendlyName: "", // Could be populated from user info UserFriendlyName: "", // Could be populated from user info
UserCanWrite: true, UserCanWrite: true,
UserCanRename: false, UserCanRename: false,
UserCanNotWriteRelative: false, UserCanNotWriteRelative: false,
ReadOnly: false, ReadOnly: false,
RestrictedWebViewOnly: false, RestrictedWebViewOnly: false,
UserCanCreateRelativeToFolder: false, UserCanCreateRelativeToFolder: false,
EnableOwnerTermination: false, EnableOwnerTermination: false,
SupportsUpdate: true, SupportsUpdate: true,
SupportsCobalt: false, SupportsCobalt: false,
SupportsLocks: true, SupportsLocks: true,
SupportsExtendedLockLength: false, SupportsExtendedLockLength: false,
SupportsGetLock: true, SupportsGetLock: true,
SupportsDelete: false, SupportsDelete: false,
SupportsRename: false, SupportsRename: false,
SupportsRenameRelativeToFolder: false, SupportsRenameRelativeToFolder: false,
SupportsFolders: false, SupportsFolders: false,
SupportsScenarios: []string{"default"}, SupportsScenarios: []string{"default"},
LastModifiedTime: file.LastModified.UTC().Format(time.RFC3339), LastModifiedTime: file.LastModified.UTC().Format(time.RFC3339),
IsAnonymousUser: false, IsAnonymousUser: false,
TimeZone: "UTC", TimeZone: "UTC",
} }
fmt.Printf("[WOPI-REQUEST] CheckFileInfo: file=%s user=%s size=%d\n", fileID, userID.String(), file.Size) fmt.Printf("[WOPI-REQUEST] CheckFileInfo: file=%s user=%s size=%d\n", fileID, userID.String(), file.Size)