Compare commits
	
		
			12 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a62ee63c83 | |||
| 
						
						
							
						
						c89f2a2939
	
				 | 
					
					
						|||
| 
						
						
							
						
						d51c58867d
	
				 | 
					
					
						|||
| 
						
						
							
						
						2fa520fdde
	
				 | 
					
					
						|||
| 
						
						
							
						
						5bb7212420
	
				 | 
					
					
						|||
| 
						
						
							
						
						2226705e3f
	
				 | 
					
					
						|||
| 72932955d1 | |||
| 
						
						
							
						
						339e2f39d8
	
				 | 
					
					
						|||
| 
						
						
							
						
						12c6d7e3da
	
				 | 
					
					
						|||
| 
						
						
							
						
						1624e666e8
	
				 | 
					
					
						|||
| 86f4cd00ea | |||
| 
						
						
							
						
						518aa3eb08
	
				 | 
					
					
						
							
								
								
									
										27
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@@ -2,9 +2,36 @@
 | 
			
		||||
 | 
			
		||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
 | 
			
		||||
 | 
			
		||||
#### [0.3.0](https://git.odit.services/kauft.es/linkylinky/compare/0.2.0...0.3.0)
 | 
			
		||||
 | 
			
		||||
- Added license [`5bb7212`](https://git.odit.services/kauft.es/linkylinky/commit/5bb7212420ba102e743d62a47074191cdb264d2a)
 | 
			
		||||
- Added stats api route [`c89f2a2`](https://git.odit.services/kauft.es/linkylinky/commit/c89f2a2939b658ffc688646ccce32fc0e1530583)
 | 
			
		||||
- Added author info [`2fa520f`](https://git.odit.services/kauft.es/linkylinky/commit/2fa520fdde1d55b2766b4b03e394e21a4f6cbae5)
 | 
			
		||||
- Updated readme [`2226705`](https://git.odit.services/kauft.es/linkylinky/commit/2226705e3f57d7d2f3ef5a79947c3ab44ec62c38)
 | 
			
		||||
- Added comments [`d51c588`](https://git.odit.services/kauft.es/linkylinky/commit/d51c58867d7508c84f26c236e38567bc6a4adbed)
 | 
			
		||||
 | 
			
		||||
#### [0.2.0](https://git.odit.services/kauft.es/linkylinky/compare/0.1.4...0.2.0)
 | 
			
		||||
 | 
			
		||||
> 14 August 2021
 | 
			
		||||
 | 
			
		||||
- 🚀RELEASE 0.2.0 [`7293295`](https://git.odit.services/kauft.es/linkylinky/commit/72932955d15976947dd553c5deba51cbf541b215)
 | 
			
		||||
- Added ebay provider recognition [`12c6d7e`](https://git.odit.services/kauft.es/linkylinky/commit/12c6d7e3da5cb4de6a597b4639f313b8e4319646)
 | 
			
		||||
- Ebay provider resolution [`339e2f3`](https://git.odit.services/kauft.es/linkylinky/commit/339e2f39d88d42a961e1e495f319dc0663cdc0a6)
 | 
			
		||||
- Now recognizing with and without protocol [`1624e66`](https://git.odit.services/kauft.es/linkylinky/commit/1624e666e83e0afe346bcacb105ea1a1535f0690)
 | 
			
		||||
 | 
			
		||||
#### [0.1.4](https://git.odit.services/kauft.es/linkylinky/compare/0.1.3...0.1.4)
 | 
			
		||||
 | 
			
		||||
> 14 August 2021
 | 
			
		||||
 | 
			
		||||
- Added cors [`518aa3e`](https://git.odit.services/kauft.es/linkylinky/commit/518aa3eb08cb72854812130d45b3b89afb074693)
 | 
			
		||||
- 🚀RELEASE 0.1.4 [`86f4cd0`](https://git.odit.services/kauft.es/linkylinky/commit/86f4cd00ea517f7e2cacbf69f2163eae597610ee)
 | 
			
		||||
 | 
			
		||||
#### [0.1.3](https://git.odit.services/kauft.es/linkylinky/compare/0.1.2...0.1.3)
 | 
			
		||||
 | 
			
		||||
> 14 August 2021
 | 
			
		||||
 | 
			
		||||
- Weired knex env fix [`fef7daa`](https://git.odit.services/kauft.es/linkylinky/commit/fef7daaf961e9112aa00f2ad22c3b0518ad258a7)
 | 
			
		||||
- 🚀RELEASE 0.1.3 [`86985ef`](https://git.odit.services/kauft.es/linkylinky/commit/86985ef7355c2db09dcd6c8e52ee7ebde3ed4128)
 | 
			
		||||
 | 
			
		||||
#### [0.1.2](https://git.odit.services/kauft.es/linkylinky/compare/0.1.1...0.1.2)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
MIT License
 | 
			
		||||
-----------
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2021 ODIT.Services (https://odit.services)
 | 
			
		||||
Permission is hereby granted, free of charge, to any person
 | 
			
		||||
obtaining a copy of this software and associated documentation
 | 
			
		||||
files (the "Software"), to deal in the Software without
 | 
			
		||||
restriction, including without limitation the rights to use,
 | 
			
		||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the
 | 
			
		||||
Software is furnished to do so, subject to the following
 | 
			
		||||
conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be
 | 
			
		||||
included in all copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 | 
			
		||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 | 
			
		||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 | 
			
		||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 | 
			
		||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 | 
			
		||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 | 
			
		||||
OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
# LinkyLinky 🔗
 | 
			
		||||
> A small url shortener, originaly developed for kauft.es
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <img height="150" src="https://git.odit.services/user/avatar/kauft.es/140">
 | 
			
		||||
  <h1 align="center">LinkyLinky 🔗</h1>
 | 
			
		||||
  <h3 align="center">A small url shortener, originaly developed for kauft.es</h3>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
## Dev Setup 🛠
 | 
			
		||||
> Runs on port 3000
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								package.json
									
									
									
									
									
								
							@@ -1,9 +1,21 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@odit/shortener-backend",
 | 
			
		||||
  "version": "0.1.3",
 | 
			
		||||
  "version": "0.3.0",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "private": false,
 | 
			
		||||
  "author": {
 | 
			
		||||
    "name": "ODIT.Services",
 | 
			
		||||
    "email": "info@odit.services",
 | 
			
		||||
    "url": "https://odit.services"
 | 
			
		||||
  },
 | 
			
		||||
  "contributors": [
 | 
			
		||||
    {
 | 
			
		||||
      "name": "Nicolai Ort",
 | 
			
		||||
      "email": "info@nicolai-ort.com",
 | 
			
		||||
      "url": "https://nicolai-ort.com"
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "dev": "nodemon src/server.js",
 | 
			
		||||
    "start": "node src/server.js",
 | 
			
		||||
@@ -15,6 +27,7 @@
 | 
			
		||||
    "dotenv": "^10.0.0",
 | 
			
		||||
    "fastify": "^3.20.1",
 | 
			
		||||
    "fastify-basic-auth": "^2.1.0",
 | 
			
		||||
    "fastify-cors": "^6.0.2",
 | 
			
		||||
    "knex": "^0.21.21",
 | 
			
		||||
    "sqlite3": "^5.0.2",
 | 
			
		||||
    "uniqid": "^5.3.0"
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,11 @@ const knex = require('knex')(knexConfiguration);
 | 
			
		||||
 | 
			
		||||
const authenticate = { realm: 'Short' }
 | 
			
		||||
fastify.register(require('fastify-basic-auth'), { validate, authenticate });
 | 
			
		||||
fastify.register(require('fastify-cors'), { 
 | 
			
		||||
    origin: true,
 | 
			
		||||
    preflight: true,
 | 
			
		||||
    preflightContinue: true
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
//Automagic Amazn redirects on /a/
 | 
			
		||||
fastify.get('/a/:id', async (req, res) => {
 | 
			
		||||
@@ -36,6 +41,11 @@ fastify.get('/ytpl/:id', async (req, res) => {
 | 
			
		||||
    res.redirect(302, `https://youtube.com/playlist?list=${req.params.id}`)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
//Automagic ebay item redirects on /e/
 | 
			
		||||
fastify.get('/e/:id', async (req, res) => {
 | 
			
		||||
    res.redirect(302, `https://ebay.de/itm/${req.params.id}`)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
//Normal shorturls
 | 
			
		||||
fastify.get('/:shortcode', async (req, res) => {
 | 
			
		||||
    const shortcode = req.params.shortcode;
 | 
			
		||||
@@ -129,6 +139,20 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => {
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
//Get stats api route
 | 
			
		||||
fastify.get('/api/stats', async (req, res) => {
 | 
			
		||||
    const urls = await knex.select('shortcode')
 | 
			
		||||
        .from('urls');
 | 
			
		||||
 | 
			
		||||
    const visits = await knex.select('timestamp')
 | 
			
		||||
        .from('visits');
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        urls: urls.length,
 | 
			
		||||
        visits: visits.length,
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
//Get url api route
 | 
			
		||||
fastify.get('/api/:shortcode', async (req, res) => {
 | 
			
		||||
    const shortcode = req.params.shortcode;
 | 
			
		||||
@@ -158,6 +182,7 @@ fastify.get('/api/:shortcode', async (req, res) => {
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//User registration
 | 
			
		||||
fastify.post('/api/register', async (req, res) => {
 | 
			
		||||
    if (!config.registrationEnabled) {
 | 
			
		||||
@@ -191,6 +216,7 @@ fastify.post('/api/register', async (req, res) => {
 | 
			
		||||
    return "Done!"
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
//Anything in here has some kind of auth
 | 
			
		||||
fastify.after(() => {
 | 
			
		||||
    //Get url api route
 | 
			
		||||
    fastify.get('/api/:shortcode/visits', { onRequest: fastify.basicAuth }, async (req, res) => {
 | 
			
		||||
@@ -279,7 +305,7 @@ function checkKnownProviders(target) {
 | 
			
		||||
            target
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    const amazonID = target.match(/https?:\/\/(www|smile|)\.?(amazon|smile)\.(de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/);
 | 
			
		||||
    const amazonID = target.match(/(?:https?:\/\/|)(www|smile|)\.?(amazon|smile)\.(de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/);
 | 
			
		||||
    if (amazonID) {
 | 
			
		||||
        const shortcode = `a/${amazonID[5]}`
 | 
			
		||||
        return {
 | 
			
		||||
@@ -288,6 +314,15 @@ function checkKnownProviders(target) {
 | 
			
		||||
            target
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    const ebayID = target.match(/(?:[ebay]*(?:[\/]|[itm=])|^)([0-9]{9,12})/);
 | 
			
		||||
    if (ebayID) {
 | 
			
		||||
        const shortcode = `e/${ebayID[1]}`
 | 
			
		||||
        return {
 | 
			
		||||
            url: `${config.getBaseUrl()}/${shortcode}`,
 | 
			
		||||
            shortcode,
 | 
			
		||||
            target
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							@@ -1249,6 +1249,14 @@ fastify-basic-auth@^2.1.0:
 | 
			
		||||
    fastify-plugin "^3.0.0"
 | 
			
		||||
    http-errors "^1.7.3"
 | 
			
		||||
 | 
			
		||||
fastify-cors@^6.0.2:
 | 
			
		||||
  version "6.0.2"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/fastify-cors/-/fastify-cors-6.0.2.tgz#4fd5102549659e9b34d252fd7ee607b63d021390"
 | 
			
		||||
  integrity sha512-sE0AOyzmj5hLLRRVgenjA6G2iOGX35/1S3QGYB9rr9TXelMZB3lFrXy4CzwYVOMiujJeMiLgO4J7eRm8sQSv8Q==
 | 
			
		||||
  dependencies:
 | 
			
		||||
    fastify-plugin "^3.0.0"
 | 
			
		||||
    vary "^1.1.2"
 | 
			
		||||
 | 
			
		||||
fastify-error@^0.3.0:
 | 
			
		||||
  version "0.3.1"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/fastify-error/-/fastify-error-0.3.1.tgz#8eb993e15e3cf57f0357fc452af9290f1c1278d2"
 | 
			
		||||
@@ -4014,6 +4022,11 @@ v8flags@^3.2.0:
 | 
			
		||||
  dependencies:
 | 
			
		||||
    homedir-polyfill "^1.0.1"
 | 
			
		||||
 | 
			
		||||
vary@^1.1.2:
 | 
			
		||||
  version "1.1.2"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
 | 
			
		||||
  integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
 | 
			
		||||
 | 
			
		||||
verror@1.10.0:
 | 
			
		||||
  version "1.10.0"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user