Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: a "delete media" option e.g. for clean-up purposes #3

Open
8go opened this issue Oct 31, 2020 · 7 comments
Open

Question: a "delete media" option e.g. for clean-up purposes #3

8go opened this issue Oct 31, 2020 · 7 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@8go
Copy link
Owner

8go commented Oct 31, 2020

  • after downloading media to local disk, maybe a "delete" option would be helpful to "clean up" on the server side
  • would be useful for archiving and reducing matrix server db size
@8go 8go changed the title consider a "delete media" option Feature request: a "delete media" option e.g. for clean-up purposes Feb 4, 2021
@8go 8go added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 5, 2021
@8go
Copy link
Owner Author

8go commented Aug 5, 2021

Anyone wanting to contribute? Anyone willing to provide a PR? Any contributions are ❤️ appreciated!

@8go
Copy link
Owner Author

8go commented Jun 3, 2022

Which matrix-nio AsyncClient API calls or logic would do such a media delete?

@8go 8go changed the title Feature request: a "delete media" option e.g. for clean-up purposes Question: a "delete media" option e.g. for clean-up purposes Jun 3, 2022
@8go 8go added the question Further information is requested label Jun 3, 2022
@8go
Copy link
Owner Author

8go commented Jun 3, 2022

See also:

HTTP API:

or

curl -XDELETE "https://SERVER_HERE/_synapse/admin/v1/media/SERVER_HERE/XMC_ID_HERE?access_token=ACCESS_TOKEN_HERE"
SERVER_HERE something like matrix.org
This curl requires ACCESS_TOKEN to have server admin rights (not room admin rights). Otherwise it returns:
curl -XDELETE "https://matrix.com/_synapse/admin/v1/media/matrix.com/XMCIDHERE?access_token=ACCESS_TOKEN_HERE"
{"errcode":"M_FORBIDDEN","error":"You are not a server admin"}

Building something around this REST API? But obly useable by server admins!

8go pushed a commit that referenced this issue Jun 5, 2022
…y-dict, --access-token

```
<   --upload UPLOAD [UPLOAD ...]
<                         Upload one or multiple files to the content
<                         repository. The files will be given a Matrix URI and
<                         stored on the server. --upload allows the optional
<                         argument --plain to skip encryption for upload.
<   --download DOWNLOAD [DOWNLOAD ...]
<                         Download one or multiple files from the content
<                         repository. You must provide one or multiple Matrix
<                         URIs (MXCs) which are strings like this
<                         'mxc://example.com/SomeStrangeUriKey'. If found they
<                         will be downloaded, decrypted, and stored in local
<                         files. If file names are specified with --file-name
<                         the downloads will be saved with these file names. If
<                         --file-name is not specified the original file name
<                         from the upload will be used. If neither specified nor
<                         'mxc-<mxc-id>' will be used. If a file name in --file-
<                         name contains the placeholder __mxc_id__, it will be
<                         replaced with the mxc-id. If a file name is specified
<                         as empty string in --file-name, then also the name
<                         'mxc-<mxc-id>' will be used. By default, the upload
<                         provided to decrypt the data. Specify one or multiple
<                         decryption keys with --key-dict. If --key-dict is not
<                         set, not decryption is attempted; and the data might
<                         be stored in encrypted fashion, or might be plain-text
<                         if the --upload skipped encryption with --plain.
<   --delete-mxc DELETE_MXC [DELETE_MXC ...]
<                         Delete one or multiple objects (e.g. files) from the
<                         content repository. You must provide one or multiple
<                         Matrix URIs (MXC) which are strings like this
<                         'mxc://example.com/SomeStrangeUriKey'. Alternatively,
<                         you can just provide the MXC id, i.e. the part after
<                         the last slash. If found they will be deleted from the
<                         server database. In order to delete objects one must
<                         have server admin permissions. Having only room admin
<                         permissions is not sufficient and it will fail. Read
<                         https://matrix-org.github.io/synapse/latest/usage/admi
<                         nistration/admin_api/ for learning how to set server
<                         admin permissions on the server. Alternatively, and
<                         optionally, one can specify an access token which has
<                         server admin permissions with the --access-token
<                         argument.
<   --file-name FILE_NAME [FILE_NAME ...]
<                         Specify one or multiple file names for some actions.
<                         This is an optional argument. Use this option in
<                         combination with options like --download to specify
<                         one or multiple file names. Ignored if used by itself
<                         without an appropriate corresponding action.
<   --key-dict KEY_DICT [KEY_DICT ...]
<                         Specify one or multiple key dictionaries for
<                         decryption. One or multiple decryption dictionaries
<                         are provided by the --upload action as a result. A
<                         decryption dictionary is a string like this: "{'v':
<                         'v2', 'key': {'kty': 'oct', 'alg': 'A256CTR', 'ext':
<                         True, 'k': 'somekey', 'key_ops': ['encrypt',
<                         'decrypt']}, 'iv': 'someiv', 'hashes': {'sha256':
<                         'someSHA'}}". If you have a list of key dictionaries
<                         and want to skip one, use the empty string.
<   --access-token ACCESS_TOKEN
<                         Set a custom access token for use by certain actions.
<                         It is an optional argument. By default --access-token
<                         is ignored and not used. It is used only by the
<                         --delete-mxc action.
```

See also Issue #3

See also matrix-nio/matrix-nio#308
@8go 8go removed help wanted Extra attention is needed good first issue Good for newcomers labels Jun 5, 2022
@8go
Copy link
Owner Author

8go commented Jun 5, 2022

--delete-mxc was implemented in commit 583a2bd

But as required by the Matrix API it requires user to have server admin permissions. See documentation.

Closing issue.

@8go 8go closed this as completed Jun 5, 2022
@8go
Copy link
Owner Author

8go commented Jun 5, 2022

Just wanted to add that I looked at the Client API (not the Admin API) and confirm that there is no "delete" operation for the content repository. So, I think what was implemented was the only available option.

See: Matrix Client API documentation: https://spec.matrix.org/latest/client-server-api

@opk12
Copy link

opk12 commented Sep 12, 2022

Yes, this is not in the specification. This issue asks to add it to the spec.

The Synapse endpoints may change in the future, because this issue asks for simplification.

Also note that Synapse supports media retention configuration since 1.61 and documented here. It auto-deletes based on the last accessed time and other configurable criteria.

For clarity / posterity, this github issue is about local media, not local copies (cache) of remote media received through federation.

@8go
Copy link
Owner Author

8go commented Oct 2, 2022

Thank you @opk12 for sharing this very relevant information.

If matrix-org/matrix-spec#226 gets implemented and (ideally) is available via matrix-nio API than it makes a lot of sense to add this new functionality to matrix-commander. I re-open the issue in the hope that there is some future development on the Matrix.org side to advance this issue.

@8go 8go reopened this Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants