Skip to content

Commit

Permalink
Merge pull request #109 from Hyleus/torrent-name
Browse files Browse the repository at this point in the history
Improve automatic torrent-naming
  • Loading branch information
HDVinnie authored Jan 6, 2018
2 parents 16d0045 + d948487 commit d23a8af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ public function upload()
// Find the right category
$category = Category::findOrFail(Request::get('category_id'));
// Create the torrent (DB)
$name = Request::get('name');
$torrent = new Torrent([
'name' => str_replace(".", " ", Request::get('name')),
'slug' => str_slug(str_replace(".", " ", Request::get('name'))),
'name' => $name,
'slug' => str_slug($name),
'description' => Request::get('description'),
'mediainfo' => Request::get('mediainfo'),
'info_hash' => $info['info_hash'],
Expand Down
24 changes: 23 additions & 1 deletion resources/views/torrent/upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@
@stop

@section('content')
<script>
function updateTorrentName() {
let name = document.querySelector("#name");
let torrent = document.querySelector("#torrent");
let fileEndings = [".mkv.torrent", ".torrent"];
let allowed = ["1.0", "2.0", "5.1", "7.1"];
if (name !== null && torrent !== null) {
let value = torrent.value.split('\\').pop().split('/').pop();
fileEndings.forEach(function(e) {
if (value.endsWith(e)) {
value = value.substr(0, value.length - e.length);
}
});
value = value.replace(/\./g, " ");
allowed.forEach(function(a) {
search = a.replace(/\./g, " ");
value = value.replace(search, a);
})
name.value = value;
}
}
</script>
@if($user->can_upload == 0)
<div class="container">
<div class="jumbotron shadowed">
Expand Down Expand Up @@ -57,7 +79,7 @@
{{ Form::open(['route' => 'upload', 'files' => true, 'class' => 'upload-form']) }}
<div class="form-group">
<label for="torrent">Torrent File</label>
<input class="upload-form-file" type="file" name="torrent" id="torrent" onchange="document.getElementById('name').value = this.value.split('\\').pop().split('/').pop()">
<input class="upload-form-file" type="file" name="torrent" id="torrent" onchange="updateTorrentName()">
</div>

<div class="form-group">
Expand Down

0 comments on commit d23a8af

Please sign in to comment.