コード例 #1
0
ファイル: views.py プロジェクト: straightedge4life/erodrive
def install_1(request):
    """
    1.Receive param from previous step,and validate it.
    2.Write into config file.
    3.Use this param to generate oauth url.
    :param request:
    :return:
    """
    params = request.POST
    if not params:
        return HttpResponseRedirect('/admin/install')
    # write into configure file

    data = {
        'client_id':
        params.get('client_id', ''),
        'client_secret':
        params.get('client_secret', ''),
        'redirect_url':
        params.get('redirect_url', ''),
        'show': [{
            'category': 'stream',
            'suffix': ['txt']
        }, {
            'category': 'image',
            'suffix': ['jpeg', 'jpg', 'png', 'gif']
        }, {
            'category': 'video',
            'suffix': ['mp4', 'mkv', 'avi']
        }, {
            'category': 'audio',
            'suffix': ['mp3', 'wav', 'ogg']
        }],
        'site_name':
        'ERO DRIVE',
        'password':
        '******',
        'access_code':
        '',
        'salt':
        helpers.rand_str(32)
    }
    helpers.batch_store_config(data)
    one = OneDrive()
    curr_url = None
    curr_host = request.get_host().split(':', -1)[0]
    if curr_host == 'localhost':
        http_referrer = request.get_raw_uri().split(':', -1)[0] + '://'
        curr_url = http_referrer + request.get_host() + '/admin/install'
    oauth_url = one.get_authorize_url()

    if curr_host == 'localhost':
        return render(request, 'install/2-local.html',
                      {'oauth_url': oauth_url})
    else:
        return render(request, 'install/2.html', {'oauth_url': oauth_url})
コード例 #2
0
ファイル: views.py プロジェクト: straightedge4life/erodrive
def install_2(request, code):
    """
    Go authorize then writen in configure file
    :param request:
    :param code:
    :return:
    """
    one = OneDrive()
    one.authorize(code)
    http_referrer = request.get_raw_uri().split(':', -1)[0] + '://'
    host = http_referrer + request.get_host()
    data = {
        'host': host,
        'password': helpers.config('password'),
        'site_name': helpers.config('site_name'),
    }
    return render(request, 'install/success.html', data)
コード例 #3
0
ファイル: views.py プロジェクト: straightedge4life/erodrive
def index(request):
    """
    List page in frontend
    :param request:
    :return:
    """
    one = OneDrive()
    path = request.GET.get('path', '/')
    item_list = helpers.list_format(one.get_list(path)['value'])

    data = {
        'item_list': item_list,
        'curr_path': '' if path == '/' else urllib.parse.quote(path),
        'path_list': helpers.path_format(path),
        'site_name': helpers.config('site_name'),
    }

    return render(request, 'home/index.html', data)
コード例 #4
0
ファイル: views.py プロジェクト: straightedge4life/erodrive
def install_0(request):
    """
    1.Generate application page url
    2.Guide user copy client id an client secret from app page and submit.
    :param request:
    :return:
    """
    host = request.get_host().split(':', -1)[0]
    if host == 'localhost':
        redirect_url = 'http://localhost:8000/admin/install'
    else:
        redirect_url = 'https://redirect.seniordriver.top'

    one = OneDrive()
    url = one.get_app_url(redirect_url)
    data = {'url': url, 'redirect_url': redirect_url}

    return render(request, 'install/1.html', data)
コード例 #5
0
ファイル: views.py プロジェクト: straightedge4life/erodrive
def detail(request):
    """
    Detail page to show the file type can show/play on website.
    :param request:
    :return:
    """
    file_path = request.GET.get('file_path', '/')
    file_name = request.GET.get('file_name')
    suffix = file_name.split('.').pop()
    suffix_cat = None
    if not file_name:
        return HttpResponseRedirect('/')
    one = OneDrive()
    file = one.get_item(file_path + '/' + file_name)
    file.update({'downloadUrl': file.get('@microsoft.graph.downloadUrl')})
    if not file:
        return HttpResponseRedirect('/')

    show_configure = eval(helpers.config('show'))
    for conf in show_configure:
        if suffix in conf['suffix']:
            suffix_cat = conf['category']

    data = {
        'file': file,
        'suffix_cat': suffix_cat,
        'site_name': helpers.config('site_name'),
        'file_name': file_name,
    }
    if suffix_cat == 'stream':
        data.update({
            'text':
            requests.get(file['downloadUrl']).text.encode('ascii', 'ignore')
        })

    if not suffix_cat:
        return HttpResponseRedirect('/?path=' + file_path)

    return render(request, 'home/detail/' + suffix_cat + '.html', data)
コード例 #6
0
 def handle(self, *args, **options):
     one = OneDrive()
     one.get_token()
     print('Refresh token successful.')
コード例 #7
0
ファイル: Upload.py プロジェクト: straightedge4life/erodrive
 async def async_upload_file(local_path: str, remote_path: str):
     await asyncio.sleep(1)
     one = OneDrive()
     res = one.upload(local_path, remote_path)
     print(res)
     print('Upload File' + local_path)
コード例 #8
0
ファイル: Upload.py プロジェクト: straightedge4life/erodrive
 def upload_file(local_path: str, remote_path: str):
     one = OneDrive()
     res = one.upload(local_path, remote_path)
     print(res)