Skip to content

Commit 1b64385

Browse files
committed
update: Dropping redundant url column from database
1 parent 7722bba commit 1b64385

File tree

12 files changed

+13
-121
lines changed

12 files changed

+13
-121
lines changed

app/Console/Commands/ImportBatchMediaCSV.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ImportBatchMediaCSV extends Command
1616
* @var string
1717
*/
1818
protected $signature = 'media:csv:batch-import
19-
{ --path= : Directory where files are located }';
19+
{ path : Directory where files are located }';
2020

2121
/**
2222
* The console command description.
@@ -42,7 +42,7 @@ public function __construct()
4242
*/
4343
public function handle(): int
4444
{
45-
$path = $this->option('path');
45+
$path = $this->argument('path');
4646
$fi = new FilesystemIterator($path);
4747
$fc = iterator_count($fi);
4848
$this->comment('Importing ' .$fc. ' CSV files into Media database...');

app/Console/Commands/ImportMediaCSV.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function __construct()
4040
*/
4141
public function handle(): int
4242
{
43+
$pattern = '(.*\/embed\/)([a-zA-Z0-9]*)(.)*';
4344
$this->comment('Starting CSV import to MySQL...');
4445
$query =
4546
'LOAD DATA INFILE "'.$this->argument('file').'" IGNORE
@@ -49,8 +50,7 @@ public function handle(): int
4950
LINES TERMINATED BY "\n"
5051
(@url, thumbnail, album, title, @tags, categories, @author, duration, views, @likes, @dislikes, @dummy, @dummy)
5152
SET author = IF(@author = "", NULL, @author),
52-
url = SUBSTRING(@url,14,45),
53-
unique_key = SUBSTRING(@url,44,15),
53+
unique_key = REGEXP_REPLACE(@url,"'.$pattern.'", "$2"),
5454
likes = IF(@likes = "", 0, @likes),
5555
dislikes = IF(@dislikes = "", 0, @dislikes),
5656
created_at = CURRENT_TIMESTAMP,
@@ -61,4 +61,4 @@ public function handle(): int
6161
$this->info('Done.');
6262
return 0;
6363
}
64-
}
64+
}

app/Media.php

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Media extends Model
2828
* @var array
2929
*/
3030
protected $fillable = [
31-
'url',
3231
'unique_key',
3332
'thumbnail',
3433
'album',
@@ -59,7 +58,6 @@ public function toSearchableArray(): array
5958
{
6059
return $this->only([
6160
'id',
62-
'url',
6361
'unique_key',
6462
'thumbnail',
6563
'album',

config/const.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
'media_new_fn' => env('MEDIA_NEW_FILE_NAME', ''),
1919
'media_new_unzipped' => env('MEDIA_NEW_FILE_UNZIPPED', ''),
2020
'media_cdn_url' => env('MEDIA_CDN_URL', ''),
21+
'media_embed_url' => env('MEDIA_EMBED_URL', ''),
2122
];

database/migrations/2020_04_13_073834_media.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public function up()
1616
Schema::create('media', function (Blueprint $table) {
1717
$table->id();
1818
$table->text('unique_key');
19-
$table->text('url');
2019
$table->text('thumbnail');
2120
$table->text('album');
2221
$table->text('title');

public/vendor/telescope/app-dark.css

-8
This file was deleted.

public/vendor/telescope/app.css

-8
This file was deleted.

public/vendor/telescope/app.js

-89
This file was deleted.

public/vendor/telescope/favicon.ico

-26 KB
Binary file not shown.

public/vendor/telescope/mix-manifest.json

-5
This file was deleted.

resources/js/views/Video.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ export default {
223223
// Clear iframe src
224224
document.getElementById('video').setAttribute('src', '')
225225
226-
let key = this.$route.params.slug
227-
key = key.substring(key.length - 15, key.length)
226+
let key = this.$route.params.slug.split('-').pop()
228227
229228
// Make the call
230229
await axios
@@ -238,7 +237,9 @@ export default {
238237
this.getRelated(12)
239238
document
240239
.querySelector('#video')
241-
.contentWindow.location.replace(this.data.url)
240+
.contentWindow.location.replace(
241+
window.embedUrl + this.data.unique_key
242+
)
242243
})
243244
.catch((error) => {
244245
console.log(error)

resources/views/master.blade.php

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<noscript><link rel="stylesheet" href="{{ mix('css/app.css') }}"></noscript>
4141

4242
<!-- Javascript -->
43+
<script>
44+
window.embedUrl = "{{ config('const.media_embed_url') }}";
45+
</script>
4346
<script src="{{ mix('js/app.js') }}" defer></script>
4447
</body>
4548
</html>

0 commit comments

Comments
 (0)