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::{ArgGroup, 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	#[command(group(
46		ArgGroup::new("direction")
47			.required(true)
48			.args(["older_than", "newer_than"]),
49	))]
50	DeleteRange {
51		/// - The relative time (e.g. 30s, 5m, 7d) within which to search
52		duration: String,
53
54		/// - Only delete media created before [duration] ago
55		#[arg(long, short)]
56		older_than: bool,
57
58		/// - Only delete media created after [duration] ago
59		#[arg(long, short)]
60		newer_than: bool,
61
62		/// - Long argument to additionally delete local media
63		#[arg(long)]
64		yes_i_want_to_delete_local_media: bool,
65	},
66
67	/// - Deletes all the local media from a local user on our server. This will
68	///   always ignore errors by default.
69	DeleteAllFromUser {
70		username: String,
71	},
72
73	/// - Deletes all remote media from the specified remote server. This will
74	///   always ignore errors by default.
75	DeleteAllFromServer {
76		server_name: OwnedServerName,
77
78		/// Long argument to delete local media
79		#[arg(long)]
80		yes_i_want_to_delete_local_media: bool,
81	},
82
83	GetFileInfo {
84		/// The MXC URL to lookup info for.
85		mxc: OwnedMxcUri,
86	},
87
88	GetRemoteFile {
89		/// The MXC URL to fetch
90		mxc: OwnedMxcUri,
91
92		#[arg(short, long)]
93		server: Option<OwnedServerName>,
94
95		#[arg(short, long, default_value("10000"))]
96		timeout: u32,
97	},
98
99	GetRemoteThumbnail {
100		/// The MXC URL to fetch
101		mxc: OwnedMxcUri,
102
103		#[arg(short, long)]
104		server: Option<OwnedServerName>,
105
106		#[arg(short, long, default_value("10000"))]
107		timeout: u32,
108
109		#[arg(long, default_value("800"))]
110		width: u32,
111
112		#[arg(long, default_value("800"))]
113		height: u32,
114	},
115
116	Preview {
117		url: Url,
118
119		/// Bypass cache
120		#[arg(short, long)]
121		no_cache: bool,
122	},
123}