1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Added shorten URL button to uploads

This commit is contained in:
Uncled1023 2016-02-24 14:58:46 -08:00
parent 8272eb95c8
commit 80fd82a5e3
5 changed files with 39 additions and 9 deletions

View File

@ -134,14 +134,19 @@
<div class="tab-pane" id="shortenedUrls">
@foreach (Teknik.Areas.Shortener.Models.ShortenedUrl url in Model.ShortenedUrls)
{
string shortUrl = Url.SubRouteUrl(string.Empty, "Shortener.View", new { url = url.ShortUrl });
if (Model.Config.DevEnvironment)
{
shortUrl = Url.SubRouteUrl("shortened", "Shortener.View", new { url = url.ShortUrl });
}
<div class="panel panel-default">
<div class="panel-heading text-center">
<a href="@url.ShortUrl">@url.OriginalUrl</a>
<a href="@shortUrl">@shortUrl</a>
</div>
<div class="panel-body">
<div class="col-sm-5 text-center">
<label for="shortUrl">Short Url</label>
<p id="shortUrl">@url.ShortUrl</p>
<p id="shortUrl"><a href="@url.OriginalUrl">@url.OriginalUrl</a></p>
</div>
<div class="col-sm-5 text-center">
<label for="dateAdded">Date Added</label>

View File

@ -25,6 +25,7 @@ namespace Teknik.Areas.Upload.Controllers
{
ViewBag.Title = "Teknik Upload - End to End Encryption";
UploadViewModel model = new UploadViewModel();
model.CurrentSub = Subdomain;
Areas.Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
{

View File

@ -74,6 +74,27 @@ function linkUploadDelete(selector, uploadID) {
});
}
function linkShortenUrl(selector, fileID, url) {
$(selector).click(function () {
$.ajax({
type: "POST",
url: shortenURL,
data: { url: url },
success: function (html) {
if (html.result) {
$(selector).prop('disabled', true);
$('#upload-link-' + fileID).html('<p><a href="' + html.result.shortUrl + '" target="_blank" class="alert-link">' + html.result.shortUrl + '</a></p>');
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + html.error + '</div>');
}
}
});
return false;
});
}
function linkRemove(selector, fileID) {
$(selector).click(function () {
$('#link-' + fileID).remove();
@ -122,7 +143,7 @@ var dropZone = new Dropzone(document.body, {
<div class="panel-footer" id="link-footer-' + fileID + '"> \
<div class="row"> \
<div class="col-sm-12 text-center"> \
<button type="button" class="btn btn-default btn-sm" id="remove-link-' + fileID + '">Remove From List</button> \
<button type="button" class="btn btn-default btn-sm" id="remove-link-' + fileID + '">Cancel Upload</button> \
</div> \
</div> \
</div> \
@ -291,7 +312,7 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) {
<button type="button" class="btn btn-default btn-sm" id="generate-delete-link-' + fileID + '">Generate Deletion URL</button> \
</div> \
<div class="col-sm-4 text-center"> \
<button type="button" class="btn btn-default btn-sm" id="remove-link-' + fileID + '">Remove From List</button> \
<button type="button" class="btn btn-default btn-sm" id="shortenUrl-button-' + fileID + '">Shorten Url</button> \
</div> \
</div> \
');
@ -302,7 +323,7 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) {
linkSaveKey('#save-key-link-' + fileID + '', name, key, fileID);
}
linkUploadDelete('#generate-delete-link-' + fileID + '', name);
linkRemove('#remove-link-' + fileID + '', fileID);
linkShortenUrl('#shortenUrl-button-' + fileID + '', fileID, fullName);
}
function uploadFailed(fileID, evt) {

View File

@ -8,6 +8,8 @@ namespace Teknik.Areas.Upload.ViewModels
{
public class UploadViewModel : ViewModelBase
{
public string CurrentSub { get; set; }
public bool SaveKey { get; set; }
public bool ServerSideEncrypt { get; set; }

View File

@ -5,14 +5,15 @@
<script>
var encScriptSrc = '@Scripts.Url("~/bundles/cryptoWorker")';
var aesScriptSrc = '@Scripts.Url("~/bundles/crypto")';
var generateDeleteKeyURL = '@Url.SubRouteUrl(Request.Url.Authority.GetSubdomain(), "Upload.Action", new { action= "GenerateDeleteKey" })';
var saveKeyToServerURL = '@Url.SubRouteUrl(Request.Url.Authority.GetSubdomain(), "Upload.Action", new { action= "SaveFileKey" })';
var removeKeyFromServerURL = '@Url.SubRouteUrl(Request.Url.Authority.GetSubdomain(), "Upload.Action", new { action= "RemoveFileKey" })';
var uploadFileURL = '@Url.SubRouteUrl(Request.Url.Authority.GetSubdomain(), "Upload.Action", new { action = "Upload" })';
var generateDeleteKeyURL = '@Url.SubRouteUrl(Model.CurrentSub, "Upload.Action", new { action= "GenerateDeleteKey" })';
var saveKeyToServerURL = '@Url.SubRouteUrl(Model.CurrentSub, "Upload.Action", new { action= "SaveFileKey" })';
var removeKeyFromServerURL = '@Url.SubRouteUrl(Model.CurrentSub, "Upload.Action", new { action= "RemoveFileKey" })';
var uploadFileURL = '@Url.SubRouteUrl(Model.CurrentSub, "Upload.Action", new { action = "Upload" })';
var maxUploadSize = @Model.Config.UploadConfig.MaxUploadSize;
var chunkSize = @Model.Config.UploadConfig.ChunkSize;
var keySize = @Model.Config.UploadConfig.KeySize;
var blockSize = @Model.Config.UploadConfig.BlockSize;
var shortenURL = '@Url.SubRouteUrl("shorten", "Shortener.Action", new { action= "ShortenUrl" })';
</script>
@Styles.Render("~/Content/upload")