diff --git a/lib/kolab_wopi/api/files.ex b/lib/kolab_wopi/api/files.ex index f33f0f4..f241516 100644 --- a/lib/kolab_wopi/api/files.ex +++ b/lib/kolab_wopi/api/files.ex @@ -1,391 +1,412 @@ defmodule KolabWopi.API.Files do use Plug.Router plug :match plug :dispatch ### ### Routes handling ### get "/:file_id" do check_file_info(conn, file_id) end get "/:file_id/contents" do get_file(conn, file_id) end get "/:file_id/ancestry" do enumerate_ancestors(conn, file_id) end get "/:file_id/ecosystem_pointer" do get_ecosystem(conn, file_id) end post "/:file_id/contents" do action = get_req_header(conn, "x-wopi-override") case action do "PUT" -> put_file(conn, file_id) _ -> send_resp(conn, 501, "Not implemented") end end post "/:file_id" do action = get_req_header(conn, "x-wopi-override") case action do "UNLOCK" -> un_lock(conn, file_id) "LOCK" -> lock(conn, file_id) "GET_LOCK" -> get_lock(conn, file_id) "REFRESH_LOCK" -> refresh_lock(conn, file_id) "PUT_RELATIVE" -> put_relative_file(conn, file_id) "RENAME_FILE" -> rename_file(conn, file_id) "DELETE" -> delete_file(conn, file_id) "PUT_USER_INFO" -> put_user_info(conn, file_id) + "GET_SHARE_URL" -> get_share_url(conn, file_id) _ -> send_resp(conn, 501, "Not implemented") end end match _ do send_resp(conn, 404, "Not found") end ### ### Action handlers ### @doc """ [GET] CheckFileInfo: Returns information about a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-SessionContext: The value of the Session context parameter. Status Codes: - 200 Success JSON Response (only required attributes listed): - BaseFileName: The string name of the file without a path. Used for display in user interface (UI), and determining the extension of the file. - OwnerId: A string that uniquely identifies the owner of the file. - Size: The size of the file in bytes, expressed as a long, a 64-bit signed integer. - UserId: A string value uniquely identifying the user currently accessing the file. - Version: The current version of the file based on the server’s file version schema, as a string. This value must change when the file changes. """ def check_file_info(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [GET] GetFile: Retrieves a file from a host. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-MaxExpectedSize: An integer specifying the upper bound of the expected size of the file being requested. Optional. The host should use the maximum value of a 4-byte integer if this value is not set in the request. Status Codes: - 200 Success - 412 File is larger than X-WOPI-MaxExpectedSize """ def get_file(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] PutFile: Updates a file’s binary contents. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "PUT". - X-WOPI-Lock: A string provided by the WOPI client in a previous Lock request. Note that this header will not be included during document creation. Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. - X-WOPI-ItemVersion: An optional string value indicating the version of the file. Its value should be the same as Version value in CheckFileInfo. Status Codes: - 200 Success - 409 Conflict: Lock mismatch/locked by another interface - 413 Request Entity Too Large: File is too large; Host limit exceeded. """ def put_file(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] PutRelativeFile: Creates a new file on the host based on the current file. The host must use the content in the POST body. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "PUT_RELATIVE". - X-WOPI-SuggestedTarget: A UTF-7 encoded string specifying either a file extension or a full file name, including the file extension. - X-WOPI-RelativeTarget: A UTF-7 encoded string that specifies a full file name including the file extension. - X-WOPI-OverwriteRelativeTarget: A Boolean value that specifies whether the host must overwrite the file name if it exists. - X-WOPI-Size: An integer that specifies the size of the file in bytes. - X-WOPI-FileConversion: A header whose presence indicates that the request is being made in the context of a binary document conversion. Body: The request body must be the full binary contents of the file. Response Headers: - X-WOPI-ValidRelativeTarget: A UTF-7 encoded string that specifies a full file name including the file extension. - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 400 Bad Request: Specified name is illegal - 409 Conflict: Target file already exists or the file is locked. - 413 Request Entity Too Large: File is too large; Host limit exceeded. JSON Response (only required attributes listed): - Name: The string name of the newly created file without a path. - Url: A string URI of the form http://server/<...>/wopi/files/(file_id)?access_token=(access token), of the newly created file on the host. """ def put_relative_file(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] RenameFile: Renames a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "RENAME_FILE". - X-WOPI-Lock: A string identifying the lock on the file. - X-WOPI-RequestedName: A UTF-7 encoded string that is a file name, not including the file extension. Response Headers: - X-WOPI-InvalidFileNameError: A string describing the reason the rename operation could not be completed. - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 400 Bad Request: Specified name is illegal - 409 Conflict: Target file already exists or the file is locked. JSON Response (only required attributes listed): - Name: The string name of the renamed file without a path or file extension. """ def rename_file(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] DeleteFile: Deletes a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "DELETE". Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 409 Conflict: Target file already exists or the file is locked. """ def delete_file(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] PutUserInfo: Stores some basic user information on the host. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "PUT_USER_INFO". Body: The request body must be the full UserInfo string. Status Codes: - 200 Success """ def put_user_info(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] Lock: Locks a file for editing. [POST] UnLockAndRelock: Releases a lock on a file, and then immediately takes a new lock on the file Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "LOCK". - X-WOPI-Lock: A string provided by the WOPI client that the host must use to identify the lock on the file. - X-WOPI-OldLock: A string provided by the WOPI client that is the existing lock on the file. Required for UnLockAndRelock. Note that if X-WOPI-OldLock is not provided, the request is identical to a Lock request. Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. - X-WOPI-ItemVersion: An optional string value indicating the version of the file. Its value should be the same as Version value in CheckFileInfo. Status Codes: - 200 Success - 400 Bad Request: X-WOPI-Lock was not provided or was empty - 409 Conflict: Lock mismatch/locked by another interface """ def lock(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] GetLock: Retrieves a lock on a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "GET_LOCK". Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 409 Conflict: Lock mismatch/locked by another interface """ def get_lock(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] RefreshLock: Refreshes the lock on a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "REFRESH_LOCK". - X-WOPI-Lock: A string provided by the WOPI client that the host must use to identify the lock on the file. Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 400 Bad Request: X-WOPI-Lock was not provided or was empty - 409 Conflict: Lock mismatch/locked by another interface """ def refresh_lock(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [POST] UnLock: Releases the lock on a file. Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Request Headers: - X-WOPI-Override: The string "UNLOCK". - X-WOPI-Lock: A string provided by the WOPI client that the host must use to identify the lock on the file. Response Headers: - X-WOPI-Lock: A string value identifying the current lock on the file. This header must always be included when responding to the request with 409. It should not be included when responding to the request with 200 OK. - X-WOPI-LockFailureReason: An optional string value indicating the cause of a lock failure. Status Codes: - 200 Success - 400 Bad Request: X-WOPI-Lock was not provided or was empty - 409 Conflict: Lock mismatch/locked by another interface """ def un_lock(conn, file_id) do conn |> send_resp(501, "Not implemented") end + @doc """ + [POST] GetShareUrl: Returns a Share URL that is suitable for viewing a shared file. + + Parameters: + - file_id: A string that specifies a file ID + Query parameters: + - access_token: Authorization token + Request Headers: + - X-WOPI-Override: The string "GET_SHARE_URL". + - X-WOPI-UrlType: A string indicating what Share URL type to return. + Status Codes: + - 200 Success + JSON Response: + - ShareUrl: A URI that points to a webpage that allows the user + to access the file. + """ + def get_share_url(conn, file_id) do + conn |> send_resp(501, "Not implemented") + end + @doc """ [GET] EnumerateAncestors Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Response Headers: - X-WOPI-EnumerationIncomplete: An optional header indicating that the enumeration of the container’s ancestry is incomplete. Status Codes: - 200 Success JSON Response (only required attributes listed): - AncestorsWithRootFirst: An array of JSON-formatted objects (Name,Url) """ def enumerate_ancestors(conn, file_id) do conn |> send_resp(501, "Not implemented") end @doc """ [GET] GetEcosystem Parameters: - file_id: A string that specifies a file ID Query parameters: - access_token: Authorization token Status Codes: - 200 Success JSON Response (only required attributes listed): - Url: A string URI for the WOPI server’s ecosystem endpoint. """ def get_ecosystem(conn, file_id) do conn |> send_resp(501, "Not implemented") end end