Skip to main content

tuwunel_admin/media/
mod.rs

1#![expect(rustdoc::broken_intra_doc_links)]
2mod delete;
3mod delete_all_from_server;
4mod delete_all_from_user;
5mod delete_by_event;
6mod delete_list;
7mod delete_range;
8mod get_file_info;
9mod get_remote_file;
10mod get_remote_thumbnail;
11mod preview;
12
13use clap::Subcommand;
14use ruma::{OwnedEventId, OwnedMxcUri, OwnedServerName};
15use tuwunel_core::Result;
16use url::Url;
17
18use crate::admin_command_dispatch;
19
20#[admin_command_dispatch]
21#[derive(Debug, Subcommand)]
22pub(super) enum MediaCommand {
23	/// - Deletes a single media file from our database and on the filesystem
24	///   via a single MXC URL
25	Delete {
26		/// The MXC URL to delete
27		#[arg(long)]
28		mxc: OwnedMxcUri,
29	},
30
31	/// - Deletes media files referenced by event
32	DeleteByEvent {
33		/// - The event ID which contains the media and thumbnail MXC URLs
34		#[arg(long)]
35		event_id: OwnedEventId,
36	},
37
38	/// - Deletes a codeblock list of MXC URLs from our database and on the
39	///   filesystem. This will always ignore errors.
40	DeleteList,
41
42	/// - Deletes all remote (and optionally local) media created before or
43	///   after [duration] time using filesystem metadata last modified at date.
44	//    This will always ignore errors by default.
45	DeleteRange {
46		/// - The relative time (e.g. 30s, 5m, 7d) within which to search
47		duration: String,
48
49		/// - Only delete media created before [duration] ago
50		#[arg(long, short)]
51		older_than: bool,
52
53		/// - Only delete media created after [duration] ago
54		#[arg(long, short)]
55		newer_than: bool,
56
57		/// - Long argument to additionally delete local media
58		#[arg(long)]
59		yes_i_want_to_delete_local_media: bool,
60	},
61
62	/// - Deletes all the local media from a local user on our server. This will
63	///   always ignore errors by default.
64	DeleteAllFromUser {
65		username: String,
66	},
67
68	/// - Deletes all remote media from the specified remote server. This will
69	///   always ignore errors by default.
70	DeleteAllFromServer {
71		server_name: OwnedServerName,
72
73		/// Long argument to delete local media
74		#[arg(long)]
75		yes_i_want_to_delete_local_media: bool,
76	},
77
78	GetFileInfo {
79		/// The MXC URL to lookup info for.
80		mxc: OwnedMxcUri,
81	},
82
83	GetRemoteFile {
84		/// The MXC URL to fetch
85		mxc: OwnedMxcUri,
86
87		#[arg(short, long)]
88		server: Option<OwnedServerName>,
89
90		#[arg(short, long, default_value("10000"))]
91		timeout: u32,
92	},
93
94	GetRemoteThumbnail {
95		/// The MXC URL to fetch
96		mxc: OwnedMxcUri,
97
98		#[arg(short, long)]
99		server: Option<OwnedServerName>,
100
101		#[arg(short, long, default_value("10000"))]
102		timeout: u32,
103
104		#[arg(long, default_value("800"))]
105		width: u32,
106
107		#[arg(long, default_value("800"))]
108		height: u32,
109	},
110
111	Preview {
112		url: Url,
113
114		/// Bypass cache
115		#[arg(short, long)]
116		no_cache: bool,
117	},
118}