Exemplo n.º 1
0
    def get(self, request, repo_id, format=None):
        repo = get_repo(repo_id)
        if not repo:
            return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')

        # generate download url for client
        ccnet_applet_root = get_ccnetapplet_root()
        relay_id = get_session_info().id
        addr, port = get_ccnet_server_addr_port ()
        email = request.user.username
        token = get_repo_token_nonnull(repo_id, request.user.username)
        repo_name = repo.name
        enc = 1 if repo.encrypted else ''
        magic = repo.magic if repo.encrypted else ''

        info_json = {
            'relay_id': relay_id,
            'relay_addr': addr,
            'relay_port': port,
            'email': email,
            'token': token,
            'repo_id': repo_id,
            'repo_name': repo_name,
            'encrypted': enc,
            'magic': magic,
            }
        return Response(info_json)
Exemplo n.º 2
0
    def get(self, request, repo_id, format=None):
        # check whether user can view repo
        repo = get_repo(repo_id)
        if not repo:
            return api_error('404')

        # if not can_access_repo(request, repo.id):
        #     return api_error('403')

        # check whether use is repo owner
        if validate_owner(request, repo_id):
            owner = "self"
        else:
            owner = "share"

        last_commit = get_commits(repo.id, 0, 1)[0].ctime
        repo.latest_modify = last_commit.ctime if last_commit else None

        # query repo infomation
        repo.size = seafserv_threaded_rpc.server_repo_size(repo_id)
        current_commit = get_commits(repo_id, 0, 1)[0]
        root_id = current_commit.root_id if current_commit else None

        # generate download url for client
        ccnet_applet_root = get_ccnetapplet_root()
        relay_id = get_session_info().id
        addr, port = get_ccnet_server_addr_port ()
        email = quote(request.user.username)
        token = get_repo_token_nonnull(repo_id, request.user.username)
        quote_repo_name = quote(repo.name.encode('utf-8'))
        enc = 1 if repo.encrypted else ''

        url = ccnet_applet_root + "/repo/download/"
        url += "?relay_id=%s&relay_addr=%s&relay_port=%s" % (relay_id, addr, port)
        url += "&email=%s&token=%s" % (email, token)
        url += "&repo_id=%s&repo_name=%s&encrypted=%s" % (repo_id, quote_repo_name, enc)
        
        repo_json = {
            "type":"repo",
            "id":repo.id,
            "owner":owner,
            "name":repo.name,
            "desc":repo.desc,
            "mtime":repo.lastest_modify,
            "size":repo.size,
            "encrypted":repo.encrypted,
            "root":root_id,
            "download_url": url,
            }

        return Response(repo_json)