def do_GET(self, serv):
    elog(('fileapi access' + serv.path))
    qs = get_qs(serv.path)
    if (('accessToken' not in qs) or (('path' not in qs) and ('id' not in qs))):
        serv.send_error(400)
        return
    tok = qs['accessToken'][0]
    userid = do_auth(tok)
    if (userid == None):
        elog('Need user id')
        print('Bad auth')
        serv.send_error(401)
        return
    path = qs['path'][0]
    if ('id' in qs):
        fileid = publicid_to_fileid(qs['id'][0])
    else:
        fileid = urllib.unquote(path)
    meta = File(fileid, userid)
    if (meta != None):
        print('DISKPATH', meta.diskpath)
    if ((meta == None) or (not os.path.exists(meta.diskpath))):
        elog('creating new file')
        cs = os.path.split(path)
        folderid = cs[0]
        f = File(folderid, userid)
        if (not os.path.exists(f.diskpath)):
            elog(('invalid folder ' + f.diskpath))
            print(('invalid folder ' + f.diskpath))
            serv.send_error(401)
            return
        if ((len(cs) == 1) or (cs[1] == '')):
            fname = cs[0]
        else:
            fname = cs[1]
        mime = 'application/octet-stream'
        f = open(((f.diskpath + '/') + fname), 'w')
        f.close()
        meta = File(fileid, userid)
    if (meta == None):
        elog('Invalid file id')
        serv.send_error(400)
        return
    print('\n\nFILE', meta, '\n\n')
    if is_folder(meta):
        elog(('target file is a folder' + meta['name']))
        serv.send_error(401)
        return
    utoken = gen_token('U', userid)
    ustatus = UploadStatus()
    ustatus.create(utoken, path, userid, fileid, (- 1))
    try:
        ustatus.commit()
    except:
        import traceback
        elog('USTATUS.COMMIT failed!')
        traceback.print_exc()
    f = open(ustatus.realpath, 'w')
    f.close()
    realpath = ustatus.realpath
    body = json.dumps({'uploadToken': utoken})
    body = bstr(body)
    print('\nupload start result:', body, '\n\n\n')
    serv.gen_headers('GET', len(body), json_mimetype)
    serv.wfile.write(body)
def do_GET(self, serv):
    elog(('fileapi access' + serv.path))
    qs = get_qs(serv.path)
    if (('accessToken' not in qs) or (('path' not in qs) and ('id' not in qs))):
        serv.send_error(400)
        return
    tok = qs['accessToken'][0]
    userid = do_auth(tok)
    if (userid == None):
        elog('Need user id')
        print('Bad auth')
        serv.send_error(401)
        return
    path = qs['path'][0]
    if ('id' in qs):
        fileid = publicid_to_fileid(qs['id'][0])
    else:
        fileid = urllib.unquote(path)
    meta = File(fileid, userid)
    if (meta != None):
        print('DISKPATH', meta.diskpath)
    if ((meta == None) or (not os.path.exists(meta.diskpath))):
        elog('creating new file')
        cs = os.path.split(path)
        folderid = cs[0]
        f = File(folderid, userid)
        if (not os.path.exists(f.diskpath)):
            elog(('invalid folder ' + f.diskpath))
            print(('invalid folder ' + f.diskpath))
            serv.send_error(401)
            return
        if ((len(cs) == 1) or (cs[1] == )):
            fname = cs[0]
        else:
            fname = cs[1]
        mime = 'application/octet-stream'
        f = open(((f.diskpath + '/') + fname), 'w')
        f.close()
        meta = File(fileid, userid)
    if (meta == None):
        elog('Invalid file id')
        serv.send_error(400)
        return
    print('\n\nFILE', meta, '\n\n')
    if is_folder(meta):
        elog(('target file is a folder' + meta['name']))
        serv.send_error(401)
        return
    utoken = gen_token('U', userid)
    ustatus = UploadStatus()
    ustatus.create(utoken, path, userid, fileid, (- 1))
    try:
        ustatus.commit()
    except:
        import traceback
        elog('USTATUS.COMMIT failed!')
        traceback.print_exc()
    f = open(ustatus.realpath, 'w')
    f.close()
    realpath = ustatus.realpath
    body = json.dumps({'uploadToken': utoken})
    body = bstr(body)
    print('\nupload start result:', body, '\n\n\n')
    serv.gen_headers('GET', len(body), json_mimetype)
    serv.wfile.write(body)