Enhance WOPI file info handler to include user-friendly name and ensure last modified time is set correctly
This commit is contained in:
@@ -247,6 +247,14 @@ func wopiCheckFileInfoHandler(w http.ResponseWriter, r *http.Request, db *databa
|
||||
|
||||
fmt.Printf("[WOPI-CheckFileInfo] START: file=%s user=%s size=%d path=%s\n", fileID, userID.String(), file.Size, file.Path)
|
||||
|
||||
// Get user info for UserFriendlyName
|
||||
user, err := db.GetUserByID(r.Context(), userID)
|
||||
if err != nil {
|
||||
fmt.Printf("[WOPI-REQUEST] Failed to get user info: user=%s error=%v\n", userID.String(), err)
|
||||
errors.WriteError(w, errors.CodeInternal, "Failed to get user info", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify user has access to this file
|
||||
canAccess := false
|
||||
var ownerID string
|
||||
@@ -269,6 +277,15 @@ func wopiCheckFileInfoHandler(w http.ResponseWriter, r *http.Request, db *databa
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure LastModifiedTime is not zero
|
||||
lastModifiedTime := file.LastModified
|
||||
if lastModifiedTime.IsZero() {
|
||||
lastModifiedTime = file.CreatedAt
|
||||
}
|
||||
if lastModifiedTime.IsZero() {
|
||||
lastModifiedTime = time.Now()
|
||||
}
|
||||
|
||||
// Build response
|
||||
response := models.WOPICheckFileInfoResponse{
|
||||
BaseFileName: file.Name,
|
||||
@@ -276,7 +293,7 @@ func wopiCheckFileInfoHandler(w http.ResponseWriter, r *http.Request, db *databa
|
||||
Version: file.ID.String(),
|
||||
OwnerId: ownerID,
|
||||
UserId: userID.String(),
|
||||
UserFriendlyName: "", // Could be populated from user info
|
||||
UserFriendlyName: user.DisplayName,
|
||||
UserCanWrite: true,
|
||||
UserCanRename: false,
|
||||
UserCanNotWriteRelative: false,
|
||||
@@ -294,7 +311,7 @@ func wopiCheckFileInfoHandler(w http.ResponseWriter, r *http.Request, db *databa
|
||||
SupportsRenameRelativeToFolder: false,
|
||||
SupportsFolders: false,
|
||||
SupportsScenarios: []string{"default"},
|
||||
LastModifiedTime: file.LastModified.UTC().Format(time.RFC3339),
|
||||
LastModifiedTime: lastModifiedTime.UTC().Format(time.RFC3339),
|
||||
IsAnonymousUser: false,
|
||||
TimeZone: "UTC",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user