Example #1
0
def reset_sync():
    data = request.json
    if not data.get('id'):
        return jsonify(error='missing id')
    Sync.update({'_id': ObjectId(data['id'])},
            {'$set': {'reserved': None}}, safe=True)
    return jsonify(result=True)
Example #2
0
def share_media():
    data = request.json
    if not data.get('id'):
        return jsonify(error='missing id')
    id = ObjectId(data['id'])
    media = Media.get(id)
    if not media:
        return jsonify(error='media %s not found' % id)
    user = data.get('user')
    if not user:
        return jsonify(error='user %s not found' % user)
    parameters = {
        'id': id,
        'path': data.get('path'),
        }
    if not Sync.add(user=ObjectId(user),
            category=media['info']['subtype'],
            parameters=parameters):
        return jsonify(error='failed to create sync')

    return jsonify(result=True)
Example #3
0
def list_syncs():
    now = datetime.utcnow()
    sync_recurrence = timedelta(minutes=Settings.get_settings('sync')['recurrence'])
    items = []
    for res in Sync.find():
        date_ = res.get('processed')
        if date_ and date_ + sync_recurrence > now:
            res['status'] = 'ok'
        else:
            res['status'] = 'pending'

        media_id = res['parameters'].get('id')
        if not media_id:
            src = res['category']
        else:
            media = Media.get(media_id)
            src = media['name'] if media else media_id

        user = get_user(res['user'])
        dst = user['name'] if user else res['user']
        res['name'] = '%s to %s' % (src, dst)
        items.append(res)

    return serialize({'result': items})
Example #4
0
def remove_sync():
    data = request.json
    if not data.get('id'):
        return jsonify(error='missing id')
    Sync.remove({'_id': ObjectId(data['id'])})
    return jsonify(result=True)
Example #5
0
        'parameters': {
            'genre_incl': params.get('genre_incl') or [],
            'genre_excl': params.get('genre_excl') or [],
            'count_max': int(count_max) if count_max else None,
            'size_max': int(size_max) if size_max else None,
            },
        }

@app.route('/sync/create', methods=['POST', 'OPTIONS'])
@crossdomain(origin='*')
def create_sync():
    try:
        sync = _get_sync(request.json)
    except SyncError, e:
        return jsonify(error=str(e))
    if not Sync.add(**sync):
        return jsonify(error='failed to create sync')
    return jsonify(result=True)

def _get_user(user):
    return {
        'id': user['_id'],
        'name': user['name'],
        'paths': user.get('paths', {}),
        }

@app.route('/sync/list', methods=['GET', 'OPTIONS'])
@crossdomain(origin='*')
def list_syncs():
    now = datetime.utcnow()
    sync_recurrence = timedelta(minutes=Settings.get_settings('sync')['recurrence'])