示例#1
0
async def siofu_start(sid, data):
  try:
    path = generate_uuid()
    filename = secure_filepath(data.get('name'))
    tmp_fs = Filesystem('tmpfs://')
    async with socketio.session(sid) as sess:
      sess['file_%d' % (data.get('id'))] = dict(
        data,
        path=path,
        name=filename,
        bytesLoaded=0,
        tmp_fs=tmp_fs,
        fh=tmp_fs.open(path, 'wb'),
      )
    await socketio.emit(
      'siofu_ready',
      {
        'id': data.get('id'),
        'name': None,
      },
      room=sid,
    )
  except Exception as e:
    logger.error(traceback.format_exc())
    await socketio.emit('siofu_error', str(e), room=sid)
示例#2
0
async def siofu_progress(sid, evt):
  async with socketio.session(sid) as sess:
    sess['file_%d' % (evt['id'])]['fh'].write(evt['content'])
  logger.debug(f"progress: {evt}")
  await socketio.emit("siofu_chunk", dict(
    id=evt['id'],
  ), room=sid)
示例#3
0
async def _(sid, data):
  ''' Broadcast livereload packets in development
  '''
  async with socketio.session(sid) as sess:
    if not sess['config']['DEBUG']:
      return
  logger.info('Live reloading...')
  await socketio.emit('livereload', data)
示例#4
0
async def siofu_done(sid, evt):
    async with socketio.session(sid) as sess:
        sess['file_%d' % (evt['id'])]['fh'].close()
        config = sess['config']
        data_fs = Filesystem(config['DATA_DIR'])
        tmp_fs = sess['file_%d' % (evt['id'])]['tmp_fs']
        path = sess['file_%d' % (evt['id'])]['path']
        filename = sess['file_%d' % (evt['id'])]['name']
        content_hash = organize_file_content(data_fs, tmp_fs, path)
        tmp_fs.close()
        del sess['file_%d' % (evt['id'])]
    #
    await socketio.emit('siofu_complete',
                        dict(id=evt['id'],
                             detail=dict(full_filename='/'.join(
                                 (content_hash, filename)), )),
                        room=sid)
示例#5
0
async def download(sid, data):
  async with socketio.session(sid) as sess:
    config = sess['config']
  #
  data_fs = Filesystem(config['DATA_DIR'])
  name = data.get('name')
  # TODO: hash based on url?
  # TODO: s3 bypass
  url = secure_url(data.get('url'))
  filename = secure_filepath(data.get('file'))
  await socketio.emit('download_queued', dict(name=name, filename=filename), room=sid)
  await download_with_progress_and_hash(
    sid=sid,
    data_fs=data_fs,
    name=name,
    url=url,
    path=generate_uuid(),
    filename=filename,
  )