def short_url(slug: str): if slug: with get_connection() as ctx: target = get_shorturl(ctx, slug) if target: return RedirectResponse(target, status_code=302) raise HTTPException(status_code=404, detail="short url not found")
def bounce_shorturl(request, slug): if slug: with get_connection() as ctx: target = get_shorturl(ctx, slug) if target: return HttpResponseRedirect(target) return HttpResponseNotFound()
def show(bot, msg): """Return a shorturl by slug.""" slug = msg.match.group(1) with shorturl_db() as ctx: target = get_shorturl(ctx, slug) if not target: msg.respond(f'shorturl `{slug}` does not exist.') else: msg.respond(target, ping=False)
def search_url(): query = request.form['searchInput'] password = pass_extract() with shorturl_db(user='******', password=password) as ctx: try: target = get_shorturl(ctx, query) except: return render_template('page.html', success='Error') else: target = target if target else "No defined shortlink" search_results = [{'name' : query, 'url' : target}] return render_template('page.html', success=None, search_results=search_results) return render_template('page.html', success='Error')