Implement automatic share link creation and logging for file sharing; make org_id nullable in file_share_links

This commit is contained in:
Leon Bösche
2026-01-24 23:45:08 +01:00
parent 82eba17a82
commit ea5c297641
4 changed files with 32 additions and 3 deletions

View File

@@ -51,12 +51,30 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
_isLoading = false;
});
} catch (e) {
// If 404 -> no share link yet. Otherwise surface error.
if (e is ApiError && e.status == 404) {
// No link exists, create one automatically
setState(() {
_shareUrl = null;
_isLoading = false;
_isLoading = true; // Keep loading for creation
});
try {
final apiClient = getIt<ApiClient>();
final path = widget.orgId.isEmpty || widget.orgId == 'personal'
? '/orgs/files/${widget.fileId}/share'
: '/orgs/${widget.orgId}/files/${widget.fileId}/share';
final response = await apiClient.postRaw(path, data: {});
setState(() {
_shareUrl = response['shareUrl'];
_isLoading = false;
});
} catch (createError) {
setState(() {
_error = createError is ApiError
? createError.message
: 'Failed to create share link';
_isLoading = false;
});
}
return;
}
setState(() {

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"net/url"
@@ -2822,6 +2823,8 @@ func createFileShareLinkHandler(w http.ResponseWriter, r *http.Request, db *data
return
}
log.Printf("Share link created: user_id=%s, file_id=%s, org_id=%v", userID, fileUUID, link.OrgID)
// Build full URL
scheme := "https"
if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" {
@@ -3154,6 +3157,8 @@ func createUserFileShareLinkHandler(w http.ResponseWriter, r *http.Request, db *
return
}
log.Printf("Share link created: user_id=%s, file_id=%s, org_id=%v", userID, fileUUID, link.OrgID)
// Build full URL
scheme := "https"
if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" {

View File

@@ -0,0 +1,3 @@
-- Make org_id nullable in file_share_links for personal file sharing
ALTER TABLE file_share_links ALTER COLUMN org_id DROP NOT NULL;

View File

@@ -0,0 +1,3 @@
-- Revert: Make org_id not nullable in file_share_links
ALTER TABLE file_share_links ALTER COLUMN org_id SET NOT NULL;