예제 #1
0
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = utils.db.query_filter(Company, journalist_folder_file_id=root).one()
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(company_id=company.id) is not True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace(
        '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'), parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': uploaded_file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name, data, parent.id, root, company, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}, 'error': True if file == 'error' else False, 'file_id': file})
예제 #2
0
def cut(json):
    file = File.get(json['params']['id'])
    if not file or not File.if_action_allowed(
            'upload',
            get_company_from_folder(json['params']['id']).id):
        return False
    return file.move_to(json['params']['folder_id'])
예제 #3
0
def send(parent_id):
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace('"','_').replace('*','_').replace('/','_').replace('\\','_'), data.get('ftype'), parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name, data, parent.id, root, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
예제 #4
0
def remove(json, file_id):
    file = File.get(file_id)
    if not file:
        return False
    ancestors = File.ancestors(file.parent_id)
    return file.remove(
        db(Company, journalist_folder_file_id=ancestors[0]).first().id)
예제 #5
0
def send(parent_id):
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(
        urllib.parse.unquote(uploaded_file.filename).replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'),
        parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename, 'description': '', 'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(
                                 chunk_size=int(data.get('chunkSize')),
                                 chunk_number=int(data.get('chunkNumber')),
                                 total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name,
                    data,
                    parent.id,
                    root,
                    content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
예제 #6
0
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = db(Company, journalist_folder_file_id=root).one()
    if FilemanagerRights(company=company).action_is_allowed(FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace(
        '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'), parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': uploaded_file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name, data, parent.id, root, company, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}, 'error': True if file == 'error' else False, 'file_id': file})
예제 #7
0
def send(parent_id):
    """ YOU SHOULD SEND PROPERTY NAME, DESCRIPTION, ROOT_FOLDER AND FOLDER.
    NOW THIS VALUES GET FROM DB. HARDCODE!!! """
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(uploaded_file.filename, data.get('ftype'), parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name, data, parent.id, root, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
예제 #8
0
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=utils.db.query_filter(Company, journalist_folder_file_id=ancestors[0]).first().id) is not True:
        return False
    return file.remove()
예제 #9
0
def cut(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=get_company_from_folder(
                    json['params']['folder_id']).id) is not True:
        return False
    return file.move_to(json['params']['folder_id'])
예제 #10
0
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=get_company_from_folder(json['params']['root_id']).id) is not True:
        return False
    return File.set_properties(file, json['params']['add_all'], name=json['params']['name'],
                               copyright_author_name=json['params']['author_name'],
                               description=json['params']['description'])
예제 #11
0
def set_properties(json):
    file = File.get(request.json['params']['id'], )
    return File.set_properties(
        file,
        request.json['params']['add_all'],
        name=request.json['params']['name'],
        copyright_author_name=request.json['params']['author_name'],
        description=request.json['params']['description'])
예제 #12
0
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or FilemanagerRights(company=get_company_from_folder(json['params']['id'])).action_is_allowed(
            FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return False
    return File.set_properties(file, json['params']['add_all'], name=json['params']['name'],
                               copyright_author_name=json['params']['author_name'],
                               description=json['params']['description'])
예제 #13
0
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or FilemanagerRights(
            company=db(Company, journalist_folder_file_id=ancestors[0]).first()).action_is_allowed(
        FilemanagerRights.ACTIONS['REMOVE'], file) != True:
        return False
    return file.remove()
예제 #14
0
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=utils.db.query_filter(
                    Company, journalist_folder_file_id=ancestors[0]).first(
                    ).id) is not True:
        return False
    return file.remove()
예제 #15
0
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or not File.if_action_allowed(
            'upload',
            get_company_from_folder(json['params']['id']).id):
        return False
    return File.set_properties(
        file,
        json['params']['add_all'],
        name=json['params']['name'],
        copyright_author_name=json['params']['author_name'],
        description=json['params']['description'])
예제 #16
0
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=get_company_from_folder(
                    json['params']['root_id']).id) is not True:
        return False
    return File.set_properties(
        file,
        json['params']['add_all'],
        name=json['params']['name'],
        copyright_author_name=json['params']['author_name'],
        description=json['params']['description'])
예제 #17
0
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = utils.db.query_filter(Company,
                                    journalist_folder_file_id=root).one()
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=company.id) is not True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(
        urllib.parse.unquote(uploaded_file.filename).replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'),
        parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {
            'title': uploaded_file.filename,
            'description': '',
            'status': 'public'
        }
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(
                                 chunk_size=int(data.get('chunkSize')),
                                 chunk_number=int(data.get('chunkNumber')),
                                 total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name,
                           data,
                           parent.id,
                           root,
                           company,
                           content=uploaded_file.stream.read(-1))
    return jsonify({
        'result': {
            'size': 0
        },
        'error': True if file == 'error' else False,
        'file_id': file
    })
예제 #18
0
def cut(json):
    file = File.get(request.json['params']['id'])
    return File.move_to(file, request.json['params']['folder_id'])
예제 #19
0
def copy(json):
    file = File.get(request.json['params']['id'])
    file.copy_file(request.json['params']['folder_id'])
    return file.id
예제 #20
0
def rename(json):
    file = File.get(request.json['params']['id'], )
    return File.rename(file, request.json['params']['name'])
예제 #21
0
def copy(json):
    file = File.get(request.json['params']['id'])
    file.copy_file(request.json['params']['folder_id'])
    return file.id
예제 #22
0
def cut(json):
    file = File.get(request.json['params']['id'])
    return File.move_to(file, request.json['params']['folder_id'])
예제 #23
0
def cut(json):
    file = File.get(json['params']['id'])
    if not file or FilemanagerRights(company=get_company_from_folder(json['params']['id'])).action_is_allowed(
            FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return False
    return file.move_to(json['params']['folder_id'])
예제 #24
0
def cropped(id):
    return render_template('cropped_image.html',
                           image=File.get(id).url()
                           )
예제 #25
0
def rename(json):
    file = File.get(request.json['params']['id'], )
    return File.rename(file, request.json['params']['name'])
예제 #26
0
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    return file.remove(db(Company, journalist_folder_file_id=ancestors[0]).first().id)
예제 #27
0
def cut(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=get_company_from_folder(json['params']['folder_id']).id) is not True:
        return False
    return file.move_to(json['params']['folder_id'])
예제 #28
0
def set_properties(json):
    file = File.get(request.json['params']['id'], )
    return File.set_properties(file, request.json['params']['add_all'], name=request.json['params']['name'],
                               copyright_author_name=request.json['params']['author_name'],
                               description=request.json['params']['description'])
예제 #29
0
def test():
    file = File.get('5644d72e-a269-4001-a5de-8c3194039273')
    name = File.set_properties(file,False,name='None', copyright_author_name='',description='')
    return render_template('tmp-test.html', file=name)