Esempio n. 1
0
 /**
  *
  * @param $path
  * @param $originDomain口
  * @param $chooserAppKey
  * @param $session
  */
 public function LinkCreateBiz($path, $originDomain, $chooserAppKey, $session)
 {
     parent::MiniBiz();
     $arr = explode('/', $path);
     $isRoot = false;
     $isMine = false;
     if (count($arr) == 3) {
         $isRoot = true;
     }
     $fileOwnerId = $arr[1];
     $currentUser = $this->user;
     $currentUserId = $currentUser['user_id'];
     if ($fileOwnerId == $currentUserId) {
         $isMine = true;
     }
     if ($isRoot && !$isMine) {
         //如果是在根目录下且不是自己的目录 则后台控制不准取消共享
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_409);
     }
     $this->originDomain = $originDomain;
     $this->appKey = $chooserAppKey;
     $this->session = $session;
     $path = MiniUtil::joinPath($path);
     $this->file = MiniFile::getInstance()->getByPath($path);
 }
Esempio n. 2
0
 /**
  *   获取events数据
  */
 public function getList($path, $time, $deviceUuid, $pageSize, $currentPage)
 {
     $user = $this->user;
     $userId = $user['id'];
     $time = $this->getTime($time);
     if ($path != "") {
         $path = MiniUtil::joinPath($path);
     }
     $total = MiniEvent::getInstance()->getTotal($path, $time, $userId, $deviceUuid);
     $totalPage = ceil($total / $pageSize);
     $events = MiniEvent::getInstance()->getByCondition($path, $userId, $time, $deviceUuid, $pageSize, ($currentPage - 1) * $pageSize);
     $itemList = array();
     $data = array();
     foreach ($events as $event) {
         $item = array();
         $device = MiniUserDevice::getInstance()->getUserDevice($event['user_device_id']);
         $item['create_user_id'] = $device['user_id'];
         $item['file_path'] = MiniUtil::getRelativePath($event['file_path']);
         $item['action'] = $event['action'];
         $item['user_name'] = $user['user_name'];
         $item['user_device_type'] = $device['user_device_type'];
         if ($device['user_id'] == $userId) {
             $item['user_self'] = true;
         } else {
             $item['user_self'] = false;
             $user = MiniUser::getInstance()->getById($device['user_id']);
             $userMetas = MiniUserMeta::getInstance()->getUserMetas($device['user_id']);
             if (isset($userMetas['nick'])) {
                 $item['user_name'] = $userMetas['nick'];
             } else {
                 $item['user_name'] = $user['user_name'];
             }
         }
         $item['created_at'] = MiniUtil::formatTime(strtotime($event['created_at']));
         $item['user_device_name'] = $device['user_device_name'];
         $item['context'] = MiniUtil::getRelativePath($event['context']);
         $item['device_uuid'] = $device['user_device_uuid'];
         if ($event['action'] == 2) {
             //判断是否是重命名还是创建
             $fromParent = CUtils::pathinfo_utf($event['file_path']);
             $toParent = CUtils::pathinfo_utf($event['context']);
             if ($fromParent['dirname'] == $toParent['dirname']) {
                 $item['action'] = MConst::RENAME;
             }
         }
         $itemList[] = $item;
     }
     $data['events'] = $itemList;
     $data['totalPage'] = $totalPage;
     return $data;
 }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
 /**
  * copy file to folder of new user
  * @param string $fileId
  * @param int $userId
  * @param int $deviceId
  * @param int $aimFolderId
  */
 public function copy($fileId, $userId, $deviceId, $aimFolderId)
 {
     $file = $this->getById($fileId);
     $aimChildren = $this->getChildrenByFileID($aimFolderId, true, null, $userId);
     //get new file name
     $aimName = $this->getFileName($file["file_name"], $aimChildren);
     $file["file_name"] = $aimName;
     //modify file path
     if ($aimFolderId === MiniFile::$ROOT_FOLDER_ID) {
         $file["file_path"] = MiniUtil::joinPath($userId, $aimName);
     } else {
         $aimFolder = $this->getById($aimFolderId);
         $file["file_path"] = MiniUtil::joinPath($aimFolder["file_path"], $aimName);
     }
     $file["parent_file_id"] = $aimFolderId;
     if ($file['file_type'] != 0) {
         $file['file_type'] = 1;
     }
     //set file.id = null
     unset($file["id"]);
     $newFile = $this->create($file, $userId);
     //create event
     MiniEvent::getInstance()->createFile($userId, $file, $deviceId);
     $metaData = array();
     $metaValue = array();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $metaData['type'] = $file['file_type'];
     $metaData['version_id'] = $file['version_id'];
     $metaData['user_id'] = $file['user_id'];
     $metaData['user_nick'] = "admin";
     $metaData['device_name'] = $device['user_device_name'];
     $metaData['file_size'] = $file['file_size'];
     $metaData['datetime'] = $file['updated_at'];
     array_push($metaValue, $metaData);
     $metaValue = serialize($metaValue);
     MiniFileMeta::getInstance()->createFileMeta($file["file_path"], "version", $metaValue);
     //copy folder
     if ($file["file_type"] !== MiniFile::$TYPE_FILE) {
         //不等于0的则为文件夹
         $children = $this->getChildrenByFileID($fileId);
         foreach ($children as $item) {
             $this->copy($item["id"], $userId, $deviceId, $newFile["id"]);
         }
     }
 }
Esempio n. 5
0
 /**
  * 判断是否是混合云版本
  */
 public static function isMixCloudVersion()
 {
     $path = MiniUtil::joinPath(MINIYUN_PATH, "protected", "plugins", "offline");
     if (file_exists($path)) {
         return false;
     }
     return true;
 }
Esempio n. 6
0
 public function invoke($uri = NULL)
 {
     $routePath = MiniHttp::getParam("route", "");
     //新接口模式
     if (!empty($routePath)) {
         //如果接口不支持匿名访问,则通过access_token初始化用户信息
         $canAnonymous = false;
         $actions = $this->anonymousActionList();
         foreach ($actions as $subAction) {
             if ($subAction === $uri) {
                 $canAnonymous = true;
             }
         }
         if ($canAnonymous === false) {
             $this->initSession();
         }
         //如接口需管理员才能访问,则需安全过滤
         $canAdmin = false;
         $actions = $this->adminActionList();
         foreach ($actions as $subAction) {
             if ($subAction === $uri) {
                 $canAdmin = true;
             }
         }
         if ($canAdmin) {
             $user = MUserManager::getInstance()->getCurrentUser();
             if (!$user["is_admin"]) {
                 throw new MiniException(100001);
             }
         }
         //通过反射方式调用对应的action
         $this->action = $uri;
         if ($this->action === "list") {
             return $this->getList();
         } else {
             $action = $this->action;
             return $this->{$action}();
         }
     } else {
         //老接口模式
         //$uri = /link/create/test/MySQL-python-1.2.3.tar
         $info = explode("/", $uri);
         $this->module = $info[1];
         $action = $info[2];
         //兼容GET方式请求数据
         $pos = strpos($action, "?");
         if ($pos !== false) {
             $action = substr($action, 0, $pos);
         }
         $this->action = $action;
         //parse path
         $path = "";
         for ($i = 3; $i < count($info); $i++) {
             $path = MiniUtil::joinPath($path, $info[$i]);
         }
         $this->path = $path;
         if ($this->action === "list") {
             return $this->getList($uri);
         } else {
             $action = $this->action;
             return $this->{$action}($uri);
         }
     }
 }