Example #1
0
 /**
  * Write a new file.
  *
  * @param string $path
  * @param string $localPath
  * @param Config $config   Config object
  *
  * @return array|false false on failure file meta data on success
  */
 public function write($path, $localPath, Config $config)
 {
     $object = $this->bucket->object($path);
     $params = [];
     $size = Storage::size($localPath);
     if ($this->isSizeBiggerForMultiPart($size)) {
         $params['multipart'] = true;
     }
     $object->write($localPath, $params);
 }
Example #2
0
 public function zipAll()
 {
     $files = TFFile::where('state', '=', 'downloaded')->get();
     $imageCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'image')->count();
     $videoCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'video')->count();
     if ($videoCount == 0 && $imageCount == 0) {
         Log::info('TFZipper : no file to be zipped.');
         return;
     }
     $fileLocs = "";
     $deleteLocs = [];
     foreach ($files as $file) {
         $deleteLocs[] = $file->location;
         $fileLocs .= ' ' . storage_path('app/' . $file->location);
         $file->state = 'zipped';
         $file->save();
     }
     $zipName = Carbon::now()->toDateString() . '.zip';
     $zipLocs = 'zip/' . $zipName;
     $cmdPass = self::PASSWORD;
     $cmdTarget = storage_path('app/' . $zipLocs);
     $cmdLocs = $fileLocs;
     $cmd = "";
     $sys = php_uname('s');
     if ($sys == 'Windows NT') {
         $cmd = $this->rarCmd;
     } else {
         if ($sys == 'Linux') {
             $cmd = $this->zipCmd;
         }
     }
     $cmd = sprintf($cmd, $cmdPass, $cmdTarget, $cmdLocs);
     if ($sys == 'Windows NT') {
         $cmd = str_replace("/", "\\", $cmd);
     }
     $result = $this->runCmd($cmd);
     if (false == $result) {
         return;
     }
     $zip = new TFZip();
     $zip->state = 'zipped';
     $zip->error = '';
     $zip->name = $zipName;
     $zip->date = Carbon::now()->toDateString();
     $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB';
     $zip->imageSize = $imageCount;
     $zip->videoSize = $videoCount;
     $zip->location = $zipLocs;
     $zip->save();
     Storage::delete($deleteLocs);
 }
Example #3
0
 public static function zipOneDay(Carbon $date)
 {
     $begin = $date->copy()->setTime(0, 0, 0);
     $end = $date->copy()->setTime(23, 59, 59);
     $deleteLocs = [];
     $videoLocs = [];
     $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($videos as $video) {
         $deleteLocs[] = $video->location;
         $videoLocs[] = storage_path('app/' . $video->location);
         $video->state = 'zipped';
         $video->save();
     }
     $imageLocs = [];
     $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($images as $image) {
         $deleteLocs[] = $image->location;
         $imageLocs[] = storage_path('app/' . $image->location);
         $image->state = 'zipped';
         $image->save();
     }
     $locs = array_merge($videoLocs, $imageLocs);
     if (count($locs) == 0) {
         Log::info('TumblrZip : no file to be ziped.');
         return;
     }
     $zipName = $begin->toDateString() . '.zip';
     $zipLocs = 'zips/' . $zipName;
     $zippy = Zippy::load();
     $zippy->create(storage_path('app/' . $zipLocs), $locs);
     $zip = new Zip();
     $zip->state = 'ziped';
     $zip->error = '';
     $zip->name = $zipName;
     $zip->date = $begin->toDateString();
     $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB';
     $zip->imageSize = count($imageLocs);
     $zip->videoSize = count($videoLocs);
     $zip->location = $zipLocs;
     $zip->save();
     Storage::delete($deleteLocs);
 }
Example #4
0
 /**
  * Download action
  *
  * @return mixed
  */
 public function download()
 {
     $filename = config('data.filename');
     return response(Storage::get($filename))->header('Content-Type', 'application/pdf')->header('Content-Length', Storage::size($filename));
 }
Example #5
0
 public function getSize()
 {
     return $this->formatSize(Storage::size($this->code));
 }