Skip to content

Commit

Permalink
index
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Oct 10, 2023
1 parent b11b57b commit f69511b
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 1 deletion.
200 changes: 200 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tShare</title>
<link href="https://fonts.cdnfonts.com/css/montserrat" rel="stylesheet">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: #5cd5fb;
font-family: Montserrat, sans-serif;
}
.container {
text-align: left;
padding:2rem;
background:#eee;
border-radius:0.5rem;
box-shadow: 2px 2px 50px 2px #4e93aa;
}
code {
display:none;
}
h1 {
margin:0;
}
p {
margin: 0 0 2rem 0 ;
}

.tab {
display: inline-block;
/* margin: 0 0 0 0px; */
padding: 10px 20px;
background-color: #333;
color: #fff;
border: 1px solid #333;
cursor: pointer;
border-top-right-radius: 4px;
border-top-left-radius: 4px;
user-select: none;
font-size: 12px;
}
.tab:hover {
background-color: #444;
}

.code-container {
background-color: #222;
border: 1px solid #333;
border-radius: 4px;
border-top-left-radius: 0;
padding: 10px 20px;
display: none;
width:600px;
}
.active {
display: block;
}
pre {
color: #5cd5fb;
font-family: 'Courier New', monospace;
}
pre.help {
font-size:10px;
color:#333;
}
.logo {
width:2rem;
}
.centered {
margin-top: 1.9rem;
text-align: center;
}

#snackbar {
visibility: hidden;
min-width: 100px;
margin-left: -50px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 0.5rem;
padding: 10px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
font-size: 15px;
}

#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.7s;
animation: fadein 0.5s, fadeout 0.5s 2.7s;
}

@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}

@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}

@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}

@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
</style>
</head>
<body>
<div class="container">
<h1>tshare</h1>
<p>the fastest way to share your files on the web, for free</p>
<div class="tab" onclick="showCode('linux',true)">Linux / macOS</div>
<div class="tab" onclick="showCode('win',true)">Windows</div>
<br>
<div id="linux-code" class="code-container">
<pre>$ curl https://tshare.download | bash<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" onclick="copyToClipboard('linux')" style="fill: white;float:right;cursor:pointer">
<path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path>
</svg></pre>
<code>curl https://tshare.download | bash</code>
</div>
<div id="win-code" class="code-container">
<pre>&gt; curl -L https://tshare.download/windows.zip -o tshare.zip <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" onclick="copyToClipboard('win')" style="fill: white;float:right;cursor:pointer">
<path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path>
</svg></pre>
<code>curl -L https://tshare.download/windows.zip -o tshare.zip</code>
</div>
<pre class="help">


<b>Usage:</b>
tshare <local-file-path> [-o remote-file-name] [-d max-downloads] [-t time-to-live-in-days] [--crypt passphrase] [--silent]
tshare --stdin -o <remote-file-name> [-d max-downloads] [-t time-to-live-in-days] [--crypt passphrase] [--silent]
tshare -r <token> [--silent]
tshare --version

<b>Options:</b>
-d Set the max number of downloads for this file.
-t Set the lifetime of this file.
-o, --output Set the filename used for sharing.
--stdin Read input from stdin.
-c, --crypt Crypt your file using gpg, if installed.
-s, --silent Less verbose, minimal output.
-r, --remove Delete and uploaded file, using a token.

<b>Examples:</b>
tshare /tmp/file1.txt # Share /tmp/file1.txt
tshare -t 3 /tmp/file2.txt # This file will be deleted in 3 days
tshare /tmp/file3.txt -o hello.txt # Uploaded as "hello.txt"
</pre>

<div class="centered">
<a href="https://github.com/trikko/tshare"><img class="logo" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTgiIGhlaWdodD0iOTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00OC44NTQgMEMyMS44MzkgMCAwIDIyIDAgNDkuMjE3YzAgMjEuNzU2IDEzLjk5MyA0MC4xNzIgMzMuNDA1IDQ2LjY5IDIuNDI3LjQ5IDMuM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snackbar">Copied!</div>

<script>
function showCode(os) {
const codeContainers = document.querySelectorAll('.code-container');
codeContainers.forEach(container => {
container.style.display = 'none';
});
document.getElementById(`${os}-code`).style.display = 'block';
// copyToClipboard(os,mode);
}
function copyToClipboard(id) {
const codeElement = document.getElementById(id + "-code").querySelector("code");
const textArea = document.createElement('textarea');
textArea.value = codeElement.textContent.trim();
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);

var x = document.getElementById("snackbar");
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
showCode('linux',false);
</script>
</body>
</html>
66 changes: 65 additions & 1 deletion source/app.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import std;
import core.atomic, core.thread;
import std.digest.sha;

immutable VERSION = "tshare/1.1";
immutable VERSION_EXT = "tshare/1.1 (https://github.com/trikko/tshare)";
Expand All @@ -11,7 +12,8 @@ enum RuntimeErrors
BadReply = -3,
GpgNotFound = -4,
CurlNotFound = -5,
FileEmpty = -6
FileEmpty = -6,
CantUpgrade = -7
}

int main(string[] args)
Expand Down Expand Up @@ -63,6 +65,7 @@ int main(string[] args)

size_t maxDownloads = size_t.max;
size_t maxDays = size_t.max;
bool upgrade = false;
bool printVersion = false;
bool fromStdin = false;
string crypt = string.init;
Expand All @@ -84,6 +87,7 @@ int main(string[] args)
"r|remove", &deleteUrl,
"c|crypt", &crypt,
"s|silent", &silent,
"upgrade", &upgrade,
"version", &printVersion
);

Expand All @@ -104,6 +108,8 @@ int main(string[] args)

if (printVersion) commands++;

if (upgrade) commands++;

if (commands != 1)
showHelp = true;
}
Expand All @@ -120,6 +126,62 @@ int main(string[] args)
showHelp = true;
}

// --version
if (!showHelp && upgrade)
{
if (args.length == 1)
{
import std.digest.sha : SHA256;

File myself = File(args[0], "r");
SHA256 sha;
ubyte[4096] data;

sha.start();
while(!myself.eof)
{
auto slice = myself.rawRead(data);
sha.put(slice);
}

string check;
string hash = sha.finish()[].toHexString().toLower();
stderr_writeln("\x1b[1mRunning version:\x1b[0m ", hash);

version(linux) auto uri = "tshare-linux-x86_64";
else version(Windows) auto uri = "tshare-windows-x86_64";
else version(OSX) auto uri = "tshare-macos-x86_64";
else auto uri = "";

uri = ("https://github.com/trikko/tshare/releases/latest/download/" ~ uri ~ ".sha256");


try {
check = cast(string) std.net.curl.get(uri).chomp;
stderr_writeln("\x1b[1mLatest version:\x1b[0m ", check, "\n");
}
catch (Exception e)
{
stderr_writeln("\x1b[1m\x1b[31mError: can't check for new updates.\x1b[0m");
return RuntimeErrors.CantUpgrade;
}

if (check != hash)
{
string upgradeCmd;
version(Windows) upgradeCmd = "curl -L https://tshare.download/windows.zip -o tshare.zip";
else upgradeCmd = "curl https://tshare.download | bash";

stderr_writeln("\x1b[32mNew version available, upgrade tshare now:\n\x1b[0m\x1b[1m", upgradeCmd, "\x1b[0m");
}
else stderr_writeln("\x1b[1mLatest version already installed.\x1b[0m");

return 0;
}

showHelp = true;
}

// -r https://transfer.sh/.../
if (!showHelp && !deleteUrl.empty)
{
Expand Down Expand Up @@ -188,6 +250,7 @@ int main(string[] args)
tshare <local-file-path> \x1b[2m[-o remote-file-name] [-d max-downloads] [-t time-to-live-in-days] [--crypt passphrase] [--silent]\x1b[0m
tshare --stdin -o <remote-file-name> \x1b[2m[-d max-downloads] [-t time-to-live-in-days] [--crypt passphrase] [--silent]\x1b[0m
tshare -r <token> \x1b[2m[--silent]\x1b[0m
tshare --upgrade
tshare --version
\x1b[32mOptions:\x1b[0m
Expand All @@ -198,6 +261,7 @@ tshare --version
\x1b[1m-c, --crypt\x1b[0m Crypt your file using gpg, if installed.
\x1b[1m-s, --silent\x1b[0m Less verbose, minimal output.
\x1b[1m-r, --remove\x1b[0m Delete and uploaded file, using a token.
\x1b[1m --upgrade\x1b[0m Is there a new tshare version available?
\x1b[32mExamples:\x1b[0m
tshare /tmp/file1.txt \x1b[1m# Share /tmp/file1.txt\x1b[0m
Expand Down

0 comments on commit f69511b

Please sign in to comment.