/** * 迷你存储报俊 * @param string $path 用户文件的存储路径 * @param string $signature 文件sha1 * @param int $size 文件大小,单位字节 * @param int $nodeId 迷你存储节点值 */ public function report($path, $signature, $size, $nodeId) { //防止重复文件通过网页上传,生成多条记录 $version = MiniVersion::getInstance()->getBySignature($signature); if (empty($version)) { //创建version/versionMeta数据 $pathParts = pathinfo($path); $type = MiniUtil::getMimeType($pathParts["basename"]); $version = MiniVersion::getInstance()->create($signature, $size, $type); MiniVersionMeta::getInstance()->create($version["id"], "store_id", $nodeId); //更新迷你存储节点状态,把新上传的文件数+1 PluginMiniStoreNode::getInstance()->newUploadFile($nodeId); //清理垃圾数据 PluginMiniBreakFile::getInstance()->deleteBySignature($signature); } //执行文件秒传逻辑 $filesController = new MFileSecondsController(); $filesController->invoke(); }
/** * (non-PHPdoc) * @see MFilesecController::invoke() */ public function invoke($uri = NULL) { $size = isset($_REQUEST['size']) ? $_REQUEST['size'] : NULL; if ($size === NULL || $size < 0) { throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . 'Missing parameter'), MConst::HTTP_CODE_400); } $hash = $_REQUEST["hash"]; $this->size = $size; $url_manager = new MUrlManager(); $path = $url_manager->parsePathFromUrl($uri); $path_info = MUtils::pathinfo_utf($path); $file_name = $path_info["basename"]; $this->type = MiniUtil::getMimeType($file_name); //如果文件的block存在则直接创建meta,表示创建成功否则返回上传文件的参数 if ($this->handleCheckFileVersionSearch($hash)) { parent::invoke($uri); } else { //空间检查 $this->spaceFilter($size); echo json_encode(array("hash" => $hash, "filename" => $file_name)); } }
/** * 文件秒传接口 */ public function sec() { $filesController = new MFileSecondsController(); $filesController->invoke(); }
/** * 文件秒传接口 */ private function files_sec() { $filesController = new MFileSecondsController(); $filesController->invoke($this->commonUri); }