Code Monkey home page Code Monkey logo

linkshortener's Introduction

linkshortener

Shorten long links using DigitalOcean Functions and an S3 backend

Installation

Support for direct installation only (App Platform TODO)

  • In the DO Functions console, create a new Namespace.
  • Create two new functions, both using the same package name (app). Make sure Web Function is checked.
    • create
    • r

Edit the create function

  • In the source code box, paste the contents of packages/app/create/__main__.py
  • Set the runtime to the latest Python version
  • Set the limits to 3 sec timeout, 128 MB memory
  • Add 4 environment variables and set the values appropriately
    • wasabi_accesskey: Access key for bucket
    • wasabi_secretkey: Secret key for bucket
    • wasabi_bucket: Bucket name
    • token: Auth token to protect this function from unauthorized use
  • Save

Edit the r function

  • In the source code box, paste the contents of packages/app/r/__main__.py
  • Repeat all of the remaining steps from the create function except adding the token environment variable.

Usage

To create a new shortened link

<FunctionURL>/app/create?u=<long-link>&t=<token>

URL Parameters

  • u: The link to shorten
  • t: The access token specified in the Installation for the create function.
  • p: An optional parameter that when set to the value echo, will return the shortened link as well as information about the request.

The return value will be the shortened link (in the form <FunctionURL>/app/r?c=<code>), a 502 HTTP code in case of an incorrect token, or an error message. Use the returned link as you would any ordinary link.

The r function has the form

<FunctionURL>/app/r?c=<code>

URL Parameters

  • c: The short code that will redirect to the designated target address

If there is an error, a 500 HTTP code will be returned.

linkshortener's People

Contributors

zoidy avatar

Stargazers

Kevin James O'Dea avatar

Watchers

Jeff Oliver avatar  avatar

linkshortener's Issues

Feat: Make deployable via App Platform

Deployment via DigitalOcean App Platform is preferable to the manual method of deployment currently supported. It enables

  • Pulling from GitHub
  • Custom domains
  • Alerting
  • Application-wide environment variables

And probably other things

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.