예제 #1
0
def peterboy_sync_config():
    """피터보이 싱크 서버 환경 설정"""

    config = PeterboySyncServer()
    config.config_key = 'Host'
    config.config_value = 'http://localhost:5002'

    db_session.add(config)
    db_session.commit()

    click.echo('서버 기본 환경 설정 값이 추가되었습니다 ')
예제 #2
0
def prepare():
    user = User(username='******', user_mail='search5', name='이지호', userpw='dmsthfl')
    db_session.add(user)
    db_session.commit()
    client = Client(
        user_id=user.id,
        client_id='anyone',
        client_secret='anyone',
        default_redirect_uri='oob',
    )
    db_session.add(client)
    db_session.commit()
예제 #3
0
    def commit_revision(cls, user_id):
        record = cls.query.filter(cls.user_id == user_id).first()
        if not record:
            record = cls()
            record.user_id = user_id
            record.latest_sync_revision = 0

            db_session.add(record)

        record.latest_sync_revision += 1

        return record.latest_sync_revision
예제 #4
0
    def post(self):
        req_json = request.get_json()

        # ID 중복 검사
        user = User.query.filter(
            User.username == req_json.get('user_id')).first()
        if user:
            return jsonify(success=False, message='가입하시려는 아이디가 있습니다')

        user = User(username=req_json.get('user_id'),
                    user_mail=req_json.get('user_email'),
                    name=req_json.get('user_name'),
                    userpw=req_json.get('user_password'))
        db_session.add(user)
        db_session.flush()

        client = new_client(user.id)
        db_session.add(client)

        login_user(user, remember=True)

        return jsonify(success=True)
예제 #5
0
파일: api.py 프로젝트: search5/peterboy
    def put(self, username, token_user=None):
        note_changes = request.get_json()['note-changes']

        guid_list = map(lambda x: x['guid'], note_changes)
        exists_notes = PeterboyNote.query.filter(
            PeterboyNote.guid.in_(guid_list),
            PeterboyNote.user_id == token_user.id)
        db_updated_guid = [exist_note.guid for exist_note in exists_notes]

        latest_sync_revision = PeterboySync.get_latest_revision(token_user.id)

        new_sync_rev = latest_sync_revision + 1

        if 'latest-sync-revision' in request.get_json():
            new_sync_rev = request.get_json()['latest-sync-revision']

        if new_sync_rev != latest_sync_revision + 1:
            # TODO: Return a more useful error response?
            return abort(500)

        for exist_note in exists_notes:
            entry = filter(lambda x: x['guid'] == exist_note.guid,
                           note_changes)
            entry = tuple(entry)[0]

            if ('command' in entry) and entry['command'] == 'delete':
                # 노트북 연결 링크도 삭제할 것...
                db_session.delete(exist_note.notebook[0])
                db_session.delete(exist_note)
                continue

            exist_note.title = entry['title']
            exist_note.note_content = entry['note-content']
            exist_note.note_content_version = entry['note-content-version']
            exist_note.last_change_date = entry['last-change-date']
            exist_note.last_metadata_change_date = entry[
                'last-metadata-change-date']
            exist_note.create_date = entry['create-date']
            exist_note.open_on_startup = entry['open-on-startup']
            exist_note.pinned = entry['pinned']
            exist_note.tags = entry['tags']
            exist_note.last_sync_revision = new_sync_rev
            exist_note.notebook[0].notebook_name = filter_notebook(
                entry['tags'])

        for entry in note_changes:
            if entry['guid'] in db_updated_guid:
                continue

            note = PeterboyNote()
            note.guid = entry['guid']
            note.user_id = token_user.id
            note.title = entry['title']
            note.note_content = entry['note-content']
            note.note_content_version = entry['note-content-version']
            note.last_change_date = entry['last-change-date']
            note.last_metadata_change_date = entry['last-metadata-change-date']
            note.last_sync_revision = new_sync_rev
            note.create_date = entry['create-date']
            note.open_on_startup = entry['open-on-startup']
            note.pinned = entry['pinned']
            note.tags = entry['tags']
            note.notebook.append(
                PeterboyNotebook(note=note,
                                 notebook_name=filter_notebook(entry['tags'])))

            db_session.add(note)

        # 마지막 싱크 리비전 저장
        latest_sync_revision = PeterboySync.commit_revision(token_user.id)

        db_session.flush()

        # 업데이트된 정보만 내려가도록 변경
        note_records = PeterboyNote.query
        notes = []

        for record in note_records:
            ref = create_ref('user_note',
                             'user_web_note',
                             username=token_user.username,
                             note_id=record.id)

            notes.append(dict(guid=record.guid, title=record.title, ref=ref))

        return jsonify({
            "latest-sync-revision": latest_sync_revision,
            "notes": notes
        })