Compare commits
No commits in common. "827c96daf5c17ef17e0993f6566eb573a49a22e8" and "acd58dbaa5dfd0d754b37d2e983061711a92814d" have entirely different histories.
827c96daf5
...
acd58dbaa5
13
README.md
13
README.md
|
@ -14,8 +14,7 @@
|
|||
sender has gone offline
|
||||
- Easy to send multiple files at once - they're bundled into a zip
|
||||
file for receivers, with zero compression so extraction is quick
|
||||
- Sanitises filenames, using sensible non-obnoxious defaults that
|
||||
should be safe across platforms
|
||||
- Sanitizes filenames
|
||||
- Fires a laser beam that turns you trans
|
||||
|
||||
## configuration
|
||||
|
@ -29,7 +28,9 @@ transbeam is configured with the following environment variables:
|
|||
|
||||
## todo
|
||||
|
||||
- uploader auth
|
||||
- downloader auth
|
||||
- delete uploads after a while
|
||||
- configurable maximum file size
|
||||
- [ ] file downloading
|
||||
- [ ] upload progress bar
|
||||
- [ ] uploader auth
|
||||
- [ ] downloader auth
|
||||
- [ ] delete uploads after a while
|
||||
- [ ] configurable maximum file size
|
||||
|
|
|
@ -11,7 +11,6 @@ use time::OffsetDateTime;
|
|||
|
||||
use crate::{file::LiveWriter, DownloadableFile, UploadedFile};
|
||||
|
||||
const MAX_FILES: usize = 256;
|
||||
const FILENAME_DATE_FORMAT: &[time::format_description::FormatItem] =
|
||||
time::macros::format_description!("[year]-[month]-[day]-[hour][minute][second]");
|
||||
|
||||
|
@ -29,12 +28,10 @@ enum Error {
|
|||
UnexpectedMessageType,
|
||||
#[error("Metadata contained an empty list of files")]
|
||||
NoFiles,
|
||||
#[error("Number of files submitted by client exceeded the maximum limit")]
|
||||
TooManyFiles,
|
||||
#[error("Websocket was closed by client before completing transfer")]
|
||||
ClosedEarly(Option<CloseReason>),
|
||||
#[error("Client sent more data than they were supposed to")]
|
||||
UnexpectedExtraData,
|
||||
TooMuchData,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
@ -46,9 +43,8 @@ impl Error {
|
|||
Self::DuplicateFilename => CloseCode::Policy,
|
||||
Self::UnexpectedMessageType => CloseCode::Invalid,
|
||||
Self::NoFiles => CloseCode::Policy,
|
||||
Self::TooManyFiles => CloseCode::Policy,
|
||||
Self::ClosedEarly(_) => CloseCode::Invalid,
|
||||
Self::UnexpectedExtraData => CloseCode::Invalid,
|
||||
Self::TooMuchData => CloseCode::Invalid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +105,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Uploader {
|
|||
let msg = match msg {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
error!("Websocket error: {}", e);
|
||||
error!("Websocket error: {:?}", e);
|
||||
ctx.stop();
|
||||
return;
|
||||
}
|
||||
|
@ -117,7 +113,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Uploader {
|
|||
|
||||
match self.handle_message(msg, ctx) {
|
||||
Err(e) => {
|
||||
error!("{}", e);
|
||||
error!("{:?}", e);
|
||||
ctx.close(Some(ws::CloseReason {
|
||||
code: e.close_code(),
|
||||
description: Some(e.to_string()),
|
||||
|
@ -164,9 +160,6 @@ impl Uploader {
|
|||
let raw_files: Vec<RawUploadedFile> = serde_json::from_slice(text.as_bytes())?;
|
||||
info!("Received file list: {} files", raw_files.len());
|
||||
debug!("{:?}", raw_files);
|
||||
if raw_files.len() > MAX_FILES {
|
||||
return Err(Error::TooManyFiles);
|
||||
}
|
||||
let mut filenames: HashSet<String> = HashSet::new();
|
||||
let mut files = Vec::new();
|
||||
for raw_file in raw_files.iter() {
|
||||
|
@ -258,7 +251,7 @@ impl Uploader {
|
|||
fn handle_data(&mut self, data: Bytes) -> Result<bool, Error> {
|
||||
if let Some(ref mut writer) = self.writer {
|
||||
if (data.len() as u64) > self.bytes_remaining {
|
||||
return Err(Error::UnexpectedExtraData);
|
||||
return Err(Error::TooMuchData);
|
||||
}
|
||||
self.bytes_remaining -= data.len() as u64;
|
||||
writer.write_all(&data)?;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="stylesheet" type="text/css" href="transbeam.css"/>
|
||||
<script src="util.js"></script>
|
||||
<title>transbeam</title>
|
||||
<title>Upload Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
|
@ -39,6 +39,6 @@
|
|||
<h5>(c) 2022 xenofem, MIT licensed</h5>
|
||||
<h5><a target="_blank" href="https://git.xeno.science/xenofem/transbeam">source</a></h5>
|
||||
</div>
|
||||
<script src="transbeam.js"></script>
|
||||
<script src="upload.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const FILE_CHUNK_SIZE = 16384;
|
||||
const MAX_FILES = 256;
|
||||
|
||||
const fileInputContainer = document.getElementById('file_input_container');
|
||||
const fileInput = document.getElementById('file_input');
|
||||
|
@ -87,7 +86,6 @@ function updateFiles() {
|
|||
uploadButton.textContent = `Upload ${files.length} file${files.length > 1 ? 's' : ''} (${displaySize(totalBytes)})`;
|
||||
uploadButton.style.display = '';
|
||||
}
|
||||
fileInput.disabled = (files.length >= MAX_FILES);
|
||||
}
|
||||
|
||||
updateFiles();
|
||||
|
@ -95,7 +93,6 @@ downloadLinkContainer.style.display = 'none';
|
|||
progressContainer.style.display = 'none';
|
||||
|
||||
function addFile(newFile) {
|
||||
if (files.length >= MAX_FILES) { return; }
|
||||
if (files.some((oldFile) => newFile.name === oldFile.name)) { return; }
|
||||
|
||||
files.push(newFile);
|
Loading…
Reference in a new issue