Skip to content

Commit b64fa36

Browse files
committed
Add a function to delete files individually
1 parent 16a6dfb commit b64fa36

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

qfieldcloud_sdk/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,26 @@ def delete_files(ctx: Context, project_id, paths, throw_on_error):
443443
log(f'Deleting project "{project_id}" files…')
444444

445445

446+
@cli.command()
447+
@click.argument("project_id")
448+
@click.argument("filename")
449+
@click.option(
450+
"--version-id",
451+
help="Pass to delete a specific file version. Otherwise the file and all it's versions will be deleted.",
452+
)
453+
@click.pass_context
454+
def delete_file(
455+
ctx: Context, project_id: str, filename: str, version_id: Optional[str]
456+
) -> None:
457+
"""Delete QFieldCloud project files."""
458+
459+
log(f'Deleting file "{filename}" in project "{project_id}"…')
460+
461+
_resp = ctx.obj["client"].delete_file(project_id, filename, version_id)
462+
463+
log(f'Successfully deleted file "{filename}" in project "{project_id}"…')
464+
465+
446466
@cli.command()
447467
@click.argument("project_id")
448468
@click.option(

qfieldcloud_sdk/sdk.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,25 @@ def delete_files(
937937

938938
return glob_results
939939

940+
def delete_file(
941+
self,
942+
project_id: str,
943+
filename: str,
944+
version_id: Optional[str],
945+
) -> requests.Response:
946+
headers = {}
947+
948+
if version_id:
949+
headers["x-file-version"] = version_id
950+
951+
resp = self._request(
952+
"DELETE",
953+
f"files/{project_id}/{filename}",
954+
headers=headers,
955+
)
956+
957+
return resp
958+
940959
def package_latest(self, project_id: str) -> Dict[str, Any]:
941960
"""Check the latest packaging status of a project.
942961

0 commit comments

Comments
 (0)