diff --git a/TODO.md b/TODO.md index c5751ff..1d8a6a9 100644 --- a/TODO.md +++ b/TODO.md @@ -12,9 +12,9 @@ - [x] Version - [x] Connection Handling - [ ] File Operations [link](https://docs.octoprint.org/en/master/api/files.html) - - [ ] Retrieve all files + - [x] Retrieve all files - [ ] Retrieve files from specific location - - [ ] Upload file or create folder + - [x] Upload file or create folder - [ ] Retrieve a specific file’s or folder’s information - [ ] Issue a file command - [ ] Delete file diff --git a/openapi/components/schemas/FileInfo.yaml b/openapi/components/schemas/FileInfo.yaml new file mode 100644 index 0000000..e69de29 diff --git a/openapi/components/schemas/RetrieveResponse.yaml b/openapi/components/schemas/RetrieveResponse.yaml new file mode 100644 index 0000000..53c1e47 --- /dev/null +++ b/openapi/components/schemas/RetrieveResponse.yaml @@ -0,0 +1,4 @@ +type: object +properties: + files: + type: s diff --git a/openapi/components/schemas/ToolInfo.yaml b/openapi/components/schemas/ToolInfo.yaml index 91bf309..a095eeb 100644 --- a/openapi/components/schemas/ToolInfo.yaml +++ b/openapi/components/schemas/ToolInfo.yaml @@ -1 +1,30 @@ type: object +properties: + length: + type: number + volume: + type: number + dimensions: + type: object + properties: + depth: + type: number + height: + type: number + width: + type: number + printingArea: + type: object + properties: + maxX: + type: number + maxY: + type: number + maxZ: + type: number + minX: + type: number + minY: + type: number + minZ: + type: number diff --git a/openapi/components/schemas/files/Filament.yaml b/openapi/components/schemas/files/Filament.yaml new file mode 100644 index 0000000..e208c88 --- /dev/null +++ b/openapi/components/schemas/files/Filament.yaml @@ -0,0 +1,55 @@ +type: object +description: The estimated usage of filament +properties: + length: + type: number + description: >- + The length of filament used, in mm + volume: + type: number + description: >- + The volume of filament used, in cm³ + dimensions: + type: object + description: >- + Information regarding the size of the printed model + properties: + depth: + type: number + description: >- + The depth of the printed model, in mm + height: + type: number + description: >- + The height of the printed model, in mm + width: + type: number + description: >- + The width of the printed model, in mm + printingArea: + type: object + properties: + maxX: + type: number + description: >- + The maximum X coordinate of the printed model, in mm + maxY: + type: number + description: >- + The maximum Y coordinate of the printed model, in mm + maxZ: + type: number + description: >- + The maximum Z coordinate of the printed model, in mm + minX: + type: number + description: >- + The minimum X coordinate of the printed model, in mm + minY: + type: number + description: >- + The minimum Y coordinate of the printed model, in mm + minZ: + type: number + description: >- + The minimum Z coordinate of the printed model, in mm diff --git a/openapi/components/schemas/files/File.yaml b/openapi/components/schemas/files/File.yaml new file mode 100644 index 0000000..b8360a6 --- /dev/null +++ b/openapi/components/schemas/files/File.yaml @@ -0,0 +1,21 @@ +type: object +required: + - origin +properties: + origin: + type: string + description: The size of the file in bytes. Only available for local files or sdcard files if the printer supports file sizes for sd card files. + enum: + - local + - sdcard + hash: + type: string + size: + type: number + date: + type: number + format: date-time + refs: + $ref: ./Reference.yaml + gcodeAnalysis: + $ref: ./GCodeAnalysis.yaml diff --git a/openapi/components/schemas/files/Folder.yaml b/openapi/components/schemas/files/Folder.yaml new file mode 100644 index 0000000..e69de29 diff --git a/openapi/components/schemas/files/GCodeAnalysis.yaml b/openapi/components/schemas/files/GCodeAnalysis.yaml new file mode 100644 index 0000000..e589c84 --- /dev/null +++ b/openapi/components/schemas/files/GCodeAnalysis.yaml @@ -0,0 +1,8 @@ +type: object +properties: + estimatedPrintTime: + type: number + description: >- + The estimated print time of the file, in seconds + filament: + $ref: "./Filament.yaml" diff --git a/openapi/components/schemas/files/Info.yaml b/openapi/components/schemas/files/Info.yaml new file mode 100644 index 0000000..6d1a138 --- /dev/null +++ b/openapi/components/schemas/files/Info.yaml @@ -0,0 +1,30 @@ +type: object +properties: + name: + type: string + description: The name of the file without path. E.g. “file.gco” for a file “file.gco” located anywhere in the file system. Currently this will always fit into ASCII. + display: + type: string + description: >- + The name of the file without the path, this time potentially with non-ASCII unicode characters. E.g. “a turtle 🐢.gco” for a file “a_turtle_turtle.gco” located anywhere in the file system. + path: + type: string + description: >- + The path to the file within the location. E.g. “folder/subfolder/file.gco” for a file “file.gco” located within “folder” and “subfolder” relative to the root of the location. Currently this will always fit into ASCII. + type: + type: string + enum: + - model + - machinecode + - folder + description: >- + Type of file. model or machinecode. Or folder if it’s a folder, in which case the children node will be populated + typePath: + type: array + items: + type: string +oneOf: + - $ref: "./File" + - $ref: "./Folder" +discriminator: + propertyName: type diff --git a/openapi/components/schemas/files/Reference.yaml b/openapi/components/schemas/files/Reference.yaml new file mode 100644 index 0000000..6ff0ecd --- /dev/null +++ b/openapi/components/schemas/files/Reference.yaml @@ -0,0 +1,13 @@ +type: object +properties: + resource: + type: string + format: url + download: + type: string + format: url + model: + type: string + format: url +required: + - resource diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 86c7119..40ca958 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -21,5 +21,11 @@ paths: $ref: paths/connection.yaml /printer: $ref: paths/printer.yaml + /files/local: + $ref: paths/files/local.yaml + /files/sdcard: + $ref: paths/files/sdcard.yaml + /files: + $ref: paths/files/get.yaml /printer/tool: $ref: paths/printer@tool.yaml diff --git a/openapi/paths/files/get.yaml b/openapi/paths/files/get.yaml new file mode 100644 index 0000000..e545c62 --- /dev/null +++ b/openapi/paths/files/get.yaml @@ -0,0 +1,16 @@ +get: + summary: Retrieve all files + operationId: getAllFiles + description: >- + Retrieve information regarding all files currently available and regarding the disk space still available locally in the system. + By default only returns the files and folders in the root directory. If the query parameter `recursive` is provided and set to `true`, returns all files and folders. + parameters: + - in: query + name: recursive + description: If set to true, return all files and folders recursively. Otherwise only return items on same level. + required: false + schema: + type: string + responses: + "200": + description: Returns a Retrieve response diff --git a/openapi/paths/files/local.yaml b/openapi/paths/files/local.yaml new file mode 100644 index 0000000..ba6fa61 --- /dev/null +++ b/openapi/paths/files/local.yaml @@ -0,0 +1,58 @@ +post: + summary: Upload file or create folder + operationId: uploadToLocal + description: Upload a file to the selected location or create a new empty folder on it. + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + file: + description: The file to upload, including a valid + type: string + format: binary + + path: + description: >- + The path within the location to upload the file to or create the folder in (without the future filename or foldername - basically the parent folder). If unset will be taken from the provided file’s name or foldername and default to the root folder of the location. + type: string + format: uri + + select: + type: boolean + description: >- + Whether to select the file directly after upload (true) or not (false). Optional, defaults to false. Ignored when creating a folder. + + print: + type: boolean + description: >- + Whether to start printing the file directly after upload (true) or not (false). If set, select is implicitly true as well. Optional, defaults to false. Ignored when creating a folder. + + userdata: + type: string + description: >- + An optional string that if specified will be interpreted as JSON and then saved along with the file as metadata (metadata key userdata). Ignored when creating a folder. + + foldername: + type: string + description: >- + The name of the folder to create. Ignored when uploading a file. + responses: + "201": + description: Created + "400": + description: >- + If no file or foldername are included in the request, userdata was provided but could not be parsed as JSON or the request is otherwise invalid. + "404": + description: >- + If location is neither local nor sdcard or trying to upload to SD card and SD card support is disabled + "409": + description: >- + If the upload of the file would override the file that is currently being printed or if an upload to SD card was requested and the printer is either not operational or currently busy with a print job. + "415": + description: >- + If the file is neither a gcode nor an stl file (or it is an stl file but slicing support is disabled) + "500": + description: >- + If the upload failed internally diff --git a/openapi/paths/files/sdcard.yaml b/openapi/paths/files/sdcard.yaml new file mode 100644 index 0000000..e501083 --- /dev/null +++ b/openapi/paths/files/sdcard.yaml @@ -0,0 +1,58 @@ +post: + summary: Upload file or create folder + operationId: uploadToSdCard + description: Upload a file to the selected location or create a new empty folder on it. + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + file: + description: The file to upload, including a valid + type: string + format: binary + + path: + description: >- + The path within the location to upload the file to or create the folder in (without the future filename or foldername - basically the parent folder). If unset will be taken from the provided file’s name or foldername and default to the root folder of the location. + type: string + format: uri + + select: + type: boolean + description: >- + Whether to select the file directly after upload (true) or not (false). Optional, defaults to false. Ignored when creating a folder. + + print: + type: boolean + description: >- + Whether to start printing the file directly after upload (true) or not (false). If set, select is implicitly true as well. Optional, defaults to false. Ignored when creating a folder. + + userdata: + type: string + description: >- + An optional string that if specified will be interpreted as JSON and then saved along with the file as metadata (metadata key userdata). Ignored when creating a folder. + + foldername: + type: string + description: >- + The name of the folder to create. Ignored when uploading a file. + responses: + "201": + description: Created + "400": + description: >- + If no file or foldername are included in the request, userdata was provided but could not be parsed as JSON or the request is otherwise invalid. + "404": + description: >- + If location is neither local nor sdcard or trying to upload to SD card and SD card support is disabled + "409": + description: >- + If the upload of the file would override the file that is currently being printed or if an upload to SD card was requested and the printer is either not operational or currently busy with a print job. + "415": + description: >- + If the file is neither a gcode nor an stl file (or it is an stl file but slicing support is disabled) + "500": + description: >- + If the upload failed internally