<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Data\Storage; use ModStart\Core\Input\Response; use ModStart\Data\AbstractDataStorage; use ModStart\Data\Event\DataFileUploadedEvent; class FileDataStorage extends AbstractDataStorage { public function init() { } public function get($ypGny) { if ($this->localStorage->has($ypGny)) { return $this->localStorage->get($ypGny); } return null; } public function size($ypGny) { return $this->localStorage->size($ypGny); } public function put($ypGny, $vVYCS) { $this->localStorage->put($ypGny, $vVYCS); } public function has($ypGny) { return $this->localStorage->has($ypGny); } public function delete($ypGny) { $this->localStorage->delete($ypGny); } public function move($lmF4G, $WLsPA) { $this->localStorage->copy($lmF4G, $WLsPA); $this->localStorage->delete($lmF4G); } public function multiPartInit($ACVUe) { goto A7KPY; A7KPY: $V6wcT = $this->multiPartInitToken($ACVUe); goto YBeID; r6D69: return Response::generate(0, 'ok', $V6wcT); goto WmiEZ; YBeID: $this->uploadChunkTokenAndUpdateToken($V6wcT); goto r6D69; WmiEZ: } public function multiPartUpload($ACVUe) { goto VT5_1; C2GuC: $zvN10['chunk'] = $vrSVj['chunk']; goto UAthi; uuYME: return Response::generate(0, 'ok', $zvN10); goto ttxjh; UAthi: $zvN10['file'] = $vrSVj['file']; goto SVEUs; a0c6B: if (!isset($vrSVj['chunk'])) { $vrSVj['chunk'] = 0; } goto Gs0uV; yDv9B: if ($zvN10['chunk'] < $zvN10['chunks']) { goto yrlpf; yrlpf: $NKf8K = $zvN10['file']->getRealPath(); goto UJATt; hEfLv: $V6wcT['chunkUploaded'] = $zvN10['chunk'] + 1; goto rgg3X; wk5lr: if ($V6wcT['chunkUploaded'] == $zvN10['chunks']) { goto wJHH4; wJHH4: $this->combine($jUKXr); goto J54_o; OSoIk: $this->move($jUKXr, $V6wcT['fullPath']); goto CPbPw; Y7mam: if ($zo4ek != $V6wcT['size']) { return Response::generate(-1, 'MultiPartUpload combile file failed (' . $zo4ek . ',' . $V6wcT['size'] . ') ShouldRetryUpload'); } goto OSoIk; sem5q: $obUh_ = $this->repository->addTemp($A1ib2, $V6wcT['path'], $V6wcT['name'], $V6wcT['size'], empty($V6wcT['md5']) ? null : $V6wcT['md5']); goto RujKf; buWqx: $zvN10['preview'] = $this->getDriverFullPath($V6wcT['fullPath']); goto fP_Z7; CPbPw: DataFileUploadedEvent::fire(null, $A1ib2, $V6wcT['fullPath']); goto sem5q; fP_Z7: $zvN10['finished'] = true; goto pUsKF; xz6Vq: $zvN10['path'] = $V6wcT['fullPath']; goto buWqx; L4OjY: $zo4ek = $this->size($jUKXr); goto Y7mam; J54_o: $this->uploadChunkTokenAndDeleteToken($V6wcT); goto L4OjY; RujKf: $zvN10['data'] = $obUh_; goto xz6Vq; pUsKF: } goto PN25i; HMk_o: $vVYCS = file_get_contents($NKf8K); goto N7grv; rgg3X: $this->uploadChunkTokenAndUpdateToken($V6wcT); goto ywJ4J; UJATt: if (false === $NKf8K) { $NKf8K = $zvN10['file']->getPathname(); } goto HMk_o; ywJ4J: $zvN10['finished'] = false; goto wk5lr; N7grv: $this->localStorage->put($jUKXr . '.' . $zvN10['chunk'], $vVYCS); goto hEfLv; PN25i: } goto uuYME; SVEUs: $jUKXr = self::DATA_CHUNK . '/data/' . $V6wcT['hash']; goto yDv9B; w0lTM: $zvN10 = array(); goto DKDRq; SBVjh: $vrSVj = $ACVUe['input']; goto VL4m3; DKDRq: if (!isset($vrSVj['chunks'])) { $vrSVj['chunks'] = 1; } goto a0c6B; Gs0uV: if (empty($vrSVj['file'])) { return Response::generateError('MultiPartUpload file empty'); } goto rZ5lW; VL4m3: $A1ib2 = $ACVUe['category']; goto w0lTM; VT5_1: $V6wcT = $this->multiPartInitToken($ACVUe); goto SBVjh; rZ5lW: $zvN10['chunks'] = $vrSVj['chunks']; goto C2GuC; ttxjh: } private function combine($ypGny) { goto tZ6BD; ncrYd: if (flock($ejffh, LOCK_EX)) { for ($kM8qX = 0;; $kM8qX++) { if (!$this->localStorage->has($ypGny . '.' . $kM8qX)) { break; } $vVYCS = file_get_contents($Av85E . $ypGny . '.' . $kM8qX); fwrite($ejffh, $vVYCS); @unlink($Av85E . $ypGny . '.' . $kM8qX); } flock($ejffh, LOCK_UN); } goto ogXUj; PrmeV: $ejffh = @fopen($Av85E . $ypGny, 'wb'); goto ncrYd; tZ6BD: $Av85E = config('filesystems.disks.data.root'); goto PrmeV; ogXUj: fclose($ejffh); goto EXVvI; EXVvI: } }