diff options
| author | Jules Laplace <carbon@melanarchy.org> | 2015-09-01 00:51:03 -0500 |
|---|---|---|
| committer | Jules Laplace <carbon@melanarchy.org> | 2015-09-01 00:51:03 -0500 |
| commit | 73a22265ab53271122bf1f47bcca6e9604c5d159 (patch) | |
| tree | c110d9f9f4079405352da49de519f35fe78faa67 /bucky2 | |
| parent | ca77a587da9ec393bceda87c2ec8dda096e2890d (diff) | |
html5 mp3 player
Diffstat (limited to 'bucky2')
| -rwxr-xr-x | bucky2/bin/move-file | 38 | ||||
| -rwxr-xr-x | bucky2/bin/rename-file | 44 |
2 files changed, 74 insertions, 8 deletions
diff --git a/bucky2/bin/move-file b/bucky2/bin/move-file index bd6dc48..7bfec85 100755 --- a/bucky2/bin/move-file +++ b/bucky2/bin/move-file @@ -4,15 +4,37 @@ use lib "../lib"; use Bucky; if (scalar(@ARGV) < 2) { - print "usage: move-file thread-id comment-id\n"; + print "usage: move-file thread-id file-ids\n"; exit(1); } -my $bucky = new Bucky; -$bucky->db->update_by_id('file', { - "id" => $ARGV[1], - "record" => { - "thread" => $ARGV[0] - } -}); +our $bucky = new Bucky; +our $thread_id = $ARGV[0]; + +for (my $i = 1; $i < scalar(@ARGV); $i++) { + move_file($ARGV[$i]); +} + +sub move_file { + my $file_id = shift; + + my $files = $bucky->db->select('file', { id => $file_id }); + my $file = $files->[0]; + + my $path = $ENV{"HOME"} . "/bucky/data/"; + + print "moving " . $file->{'filename'} . "\n"; + + system("/bin/mkdir", "-p", $path . $thread_id); + system("/bin/mkdir", "-p", $path . $thread_id . "/.thumb"); + system("/bin/mv", $path . $file->{'thread'} . "/" . $file->{'filename'}, $path . $thread_id); + + $bucky->db->update_by_id('file', { + "id" => $file_id, + "record" => { + "thread" => $thread_id + } + }); +} + diff --git a/bucky2/bin/rename-file b/bucky2/bin/rename-file new file mode 100755 index 0000000..a060b1a --- /dev/null +++ b/bucky2/bin/rename-file @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use strict; +use lib "../lib"; +use Bucky; + +if (scalar(@ARGV) < 2) { + print "usage: move-file file-id filename\n"; + exit(1); +} + +our $bucky = new Bucky; +our $file_id = $ARGV[0]; +our $filename = $ARGV[1]; + +rename_file($file_id, $filename); + +sub rename_file { + my ($file_id, $filename) = @_; + + my $files = $bucky->db->select('file', { id => $file_id }); + my $file = $files->[0]; + + my $path = $ENV{"HOME"} . "/bucky/data/"; + + print $path . $file->{'thread'} . "/" . $filename . "\n"; + if (-e $path . $file->{'thread'} . "/" . $filename) { + print "file exists!\n"; + return + } + print "renaming " . $file->{'filename'} . " => " . $filename . "\n"; + + system("/bin/mv", + $path . $file->{'thread'} . "/" . $file->{'filename'}, + $path . $file->{'thread'} . "/" . $filename); + + $bucky->db->update_by_id('file', { + "id" => $file_id, + "record" => { + "filename" => $filename + } + }); +} + + |
