Skip to content

Latest commit

 

History

History
382 lines (358 loc) · 6.84 KB

File metadata and controls

382 lines (358 loc) · 6.84 KB

Fileknight API Docs

AUTH API (/api/auth)

Register:

This is used for finishing the registration process. The user entity is created by the server's admin, this api just sets finished registration (sets the password) using the received token

POST /api/auth/register
{
   username: (required) User's unique username
   password: (required) User's password
   token:    (required) Token used for registration. Received from server admin
}
Sample response
{
    "success": true,
    "message": "User successfully registered.",
    "data": {
        "id":,
        "username":,
        "roles": ["ROLE_USER"],
        "createdAt":
    },
    "status": 201
}

Login:

POST /api/auth/login
{
    username:
    password:
}
Sample response:
{
    "jwt":
    "iat":
    "exp":
    "refresh_token":
}

Refresh jwt token

Refresh the JWT. Returns a new JWT and a new refresh token

POST /api/auth/refresh
{
    refresh_token: (required) The refresh token
}
Sample response:
{
    "jwt":
    "iat":
    "exp":
    "refresh_token":
}

Request a password reset

Request a password reset. Passwords reset are handled by the admin, this endpoint just sends the request, the new reset token will be generated by the admin and sent to the user. After receiving the reset token, use the same register endpoint to set the new password.

POST /api/auth/{userId}/reset
Sample response
{
    "success": true,
    "message": "Password reset request sent. You will be contacted by the admin.",
    "data": [],
    "status": 200
}

Change password

PATCH /api/auth/{userId}/edit/password
{
    oldPassword: (required) User's old password
    newPassword: (required) User's new password
}
Sample response
{
    "success": true,
    "message": "Password successfully changed.",
    "data": {
        "id":,
        "username":,
        "roles": ["ROLE_USER"],
        "createdAt":
    },
    "status": 201
}

Logout

POST /api/auth/logout
Headers: Fk-Device-Id
Sample response
{
    "success": true,
    "message": "User successfully logged out from device: <device>",
    "data": [],
    "status": 200
}

Logout from all devices

POST /api/auth/logout/all
Sample response
{
    "success": true,
    "message": "User successfully logged out from all devices",
    "data": [],
    "status": 200
}

List all sessions

GET /api/auth/sessions
Sample response
{
    "success": true,
    "message": "Active sessions fetched.",
    "data": [
        {
            "token":,
            "issued_at":
            "userAgent":
            "deviceId":
            "ip":
        }
    ],
    "status": 200
}

FILES API (/api/files)

List content:

List the content of the directory given by the parentId query param. If parentId is not given return the content of root directory.

GET /api/files?parentId={id}
Sample response:
{
    "success": true,
    "message": "SUCCESS",
    "data": {
        "id":
        "name":
        "directories": [
            {
                "id":
                "name":
                "createdAt":
                "updatedAt": 
            }
        ],
        "files": [
            {
                "id":
                "name":
                "size": 
                "mimeType":
                "extension": 
                "createdAt": 
                "updatedAt":
            }
        ]
    },
    "status": 200
}

Upload file

POST /api/files
{
    file:     <file>
    parentId: (required) The folder in which to upload it. If null upload in root
    name:     (optional) The name to upload the file with. If not specified or null use the original file name
}
Sample response:
{
    "success": true,
    "message": "File uploaded successfully.",
    "data": {
        "id":
        "name":
        "size":
        "extension":
        "createdAt":
        "updatedAt":
    },
    "status": 200
}

Update file - rename / move

PATCH /api/files/{id}
{
    parentId: (optional) The file's new parent folder. If null new parent is root
    name:     (optional) The file's new name
}
Sample response:
{
    "success": true,
    "message": "File updated successfully.",
    "data": {
        "id":
        "name":
        "size":
        "extension":
        "createdAt":
        "updatedAt":
    },
    "status": 200
}

Delete file

DELETE /api/files/{id}
Sample response:
{
    "success": true,
    "message": "File {id} deleted successfully.",
    "data": [],
    "status": 200
}

Get folder metadata

GET /api/files/folders/{id}
Sample response:
{
    "ancestors": [
      {
        "id":
        "name":
      },
      ...
    }
}

Create folder

POST /api/files/folders
{
    name:     (required) Folder's name
    parentId: (required) Folder's parent. If null create in root
}
Sample response:
{
    "success": true,
    "message": "Directory created successfully.",
    "data": {
        "id":
        "name":
        "createdAt":
        "updatedAt":
    },
    "status": 200
}

Update folder - rename / move

PATCH /api/files/folders/{id}
{
    parentId: (optional) Folder's new parent folder. If null the new parent will be root
    name:     (optional) Folder's new name
}
Sample response:
{
    "success": true,
    "message": "Folder updated successfully.",
    "data": {
        "id":
        "name":
        "createdAt":
        "updatedAt":
    },
    "status": 200
}

Delete folder

DELETE /api/files/folders/{id}
Sample response:
{
    "success": true,
    "message": "Folder {id} deleted successfully.",
    "data": [],
    "status": 200
}

Download

POST /api/files/download
{
    folderIds: (optional) Array containing the ids of the folders to download
    fileIds:   (optional) Array containing the ids of the files to download
}

Error response

All error responses have the following structure:

{
    "success": false,
    "error": "ERROR_CODE",
    "message": "Descriptive error message",
    "details": {
        Object containing specific details about this error
    },
    "status": STATUS_CODE
}