/** * 静态方法, 单例统一访问入口 * @return object 返回对象的唯一实例 */ public static function getInstance() { if (is_null(self::$_instance) || !isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
public function delete($path) { $userId = $this->user["id"]; $absolutePath = MiniUtil::joinPath($path); $file = MiniFile::getInstance()->getByPath($absolutePath); $id = $file['id']; $link = MiniLink::getInstance()->getByFileId($id); $linkId = $link["id"]; $share = MiniLink::getInstance()->deleteById($userId, $id); MiniChooserLink::getInstance()->deleteByLinkId($linkId); if ($share) { return true; } else { return false; } }
/** * 形成最终第三方所需数据 */ public function generateFileData($appKey, $session, $linkType) { //todo appKey检测 if ($linkType != MiniLink::$DIRECT_LINK) { $linkType = MiniLink::$PREVIEW_LINK; } $links = MiniChooserLink::getInstance()->getBySession($session); foreach ($links as $link) { $files = MiniLink::getInstance()->getById($link['link_id']); $fileId = $files['file_id']; $shareKey = $files['share_key']; $fileInfo = $this->getLink($fileId, $linkType, $shareKey); $filesInfo['list'][] = $fileInfo; } $filesInfo['success'] = true; if ($filesInfo['list'] == null) { $filesInfo['success'] = false; } return $filesInfo; }
/** * 创建外链 */ public function createLink($linkType, $password, $expiryTime) { $result = $this->valid(); if ($result["success"] === false) { return $result; } $file = $this->file; //创建外链 $link = MiniLink::getInstance()->create($this->user["id"], $file["id"], $password, $expiryTime); //创建外链属性 MiniChooserLink::getInstance()->create($link["id"], $this->appKey, $this->session); //返回直链或预览链接 $data = array(); $data["success"] = true; $data["name"] = $file["file_name"]; $data["bytes"] = intval($file["file_size"] + ""); //获得文件的icon $fileType = $file["file_type"]; //根据文件后缀,如果为jpg/jpeg/gif/png就直接显示缩略图 $ext = MiniUtil::getFileExtension($file["file_name"]); if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") { $data["thumbnail_link"] = MiniHttp::createUrl("link/thumbnail/key/" . $link["share_key"]); } else { $data["thumbnail_link"] = ""; } if ($linkType == MiniLink::$PREVIEW_LINK) { $data["link"] = MiniHttp::createUrl("link/access/key/" . $link["share_key"]); } else { $data["link"] = MiniHttp::createUrl("link/direct/key/" . $link["share_key"]); } return $data; }