Skip to main content

tuwunel_admin/media/
mod.rs

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