Implement automatic share link creation and logging for file sharing; make org_id nullable in file_share_links
This commit is contained in:
@@ -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(() {
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user