Beispiel #1
0
def _upload_to_sftp_server(server, publication):
    parameters = extract_parameters(server.parameters)
    
    from storages.backends.sftpstorage import SFTPStorage
    root_path = '%s%s' % (parameters.pop('root_path'), publication.get_parent_folder())
    SFTPStorage(server.server_address, root_path, parameters).save('%s.%s' % (publication.uid, publication.file_ext), publication.uploaded_file)

    return True
Beispiel #2
0
def _generate_nginx_download_url(server, publication):
    """
    Serve file using nginx's HttpSecureLinkModule
    """
    parameters = extract_parameters(server.parameters)

    path = parameters.get('prefix') + publication.get_download_rel_path()
    expire_timestamp = int(time()) + settings.DOWNLOAD_LINK_EXPIRE_IN * 60

    import hashlib, base64
    m = hashlib.md5()
    m.update('%s%s%s' % (parameters.get('secret'), path, expire_timestamp))
    hash = base64.urlsafe_b64encode(m.digest())
    hash = hash.replace('=', '')
    hash = hash.replace('+', '-')
    hash = hash.replace('/', '_')
    return 'http://%s%s?st=%s&e=%s' % (server.server_address, path, hash, expire_timestamp)