Exemplo n.º 1
0
def view_raw(slug):
    paste = Paste.get_or_404(slug)
    if paste.password and not paste.verify_password(request.form.get('p', '')):
        abort(401)

    if paste.is_resource:
        return redirect(paste.generate_presigned_resource_url())

    return Response(response=paste.source, status=200, mimetype='text/plain')
Exemplo n.º 2
0
def view(slug):
    paste = Paste.get_or_404(slug)
    if paste.password:
        return jsonify(code=401)

    return jsonify(
        code=200,
        paste=dict(
            title=paste.title,
            source=paste.source,
            view_count=paste.view_count,
            created_at=int(paste.created_at.timestamp()),
            expire_at=int(paste.expire_at.timestamp())
            if paste.expire_at else None,
            secret=paste.password is not None,
        ),
    )
Exemplo n.º 3
0
def view(slug):
    paste = Paste.get_or_404(slug)
    password = None
    if paste.password:
        form = PasswordForm()
        if form.validate_on_submit():
            if not paste.verify_password(form.password.data):
                flash('비밀번호가 일치하지 않습니다.', 'error')
                return render_template('password.html', form=form)
            password = form.password.data
        else:
            form.flash_errors()
            return render_template('password.html', form=form)

    viewed = session.setdefault('viewed', [])
    if paste.slug not in viewed:
        viewed.append(paste.slug)
        session.permanent = True
        session.modified = True
        paste.view_count += 1
        db.session.add(paste)
        db.session.commit()

    lexer = get_lexer_by_name(paste.lexer)
    formatter = HtmlFormatter(
        linenos=True,
        linespans='line',
        lineanchors='line',
        anchorlinenos=True,
    )

    return render_template(
        'view.html',
        styles=formatter.get_style_defs(),
        highlighted_source=highlight(paste.source, lexer, formatter),
        lexer=lexer,
        paste=paste,
        password=password,
    )