Skip to content

Commit 074596b

Browse files
authored
Merge pull request #4 from andreazorzi/development
v1.0.0
2 parents 68811b0 + bff2afb commit 074596b

File tree

259 files changed

+3522
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+3522
-219
lines changed

.env-example renamed to .env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ DB_USERNAME=sail
1313
DB_PASSWORD=password
1414

1515
ADMIN_USERNAME="admin"
16-
ADMIN_PASSWORD="password"
16+
ADMIN_PASSWORD="password"
17+
18+
# Decomment for API
19+
# API_TOKEN=very_strong_token

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ yarn-error.log
1717
/.idea
1818
/.vscode
1919
composer.lock
20-
package-lock.json
20+
package-lock.json
21+
docker-compose.local.yml

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RUN dnf update -y \
1414
php-msgpack php-igbinary php-redis \
1515
php-memcached php-pcov php-xdebug -y \
1616
&& dnf install supervisor -y
17-
RUN dnf install php-swoole --nobest -y
17+
RUN dnf install php-swoole --nobest -y
18+
RUN dnf install mysql -y
1819
RUN mkdir -p /run/php-fpm/
1920

2021
RUN curl https://getmic.ro | bash && mv micro /usr/bin/

README.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
1-
# PicoLink
1+
<p align="center">
2+
<img src="https://github.com/andreazorzi/PicoLink/blob/development/public/images/logo.png?raw=true" alt="PicoLink" width="400"/>
3+
</p>
4+
<br>
5+
PicoLink is not the regular url shortner. It provide super power to your links.
6+
7+
## ⚡️ Super Powers
8+
- Custom short link code, even with emojis: https://yoursite.com/🚀
9+
- Customized tags and advanced search to find your shorts faster 🔎
10+
- Quick sharing and qrcode creation 💻
11+
- Complete reports with visits by day, devices, referrers and countries 📊
12+
- Simple API for createating new shorts 🤖
13+
- Multilingual short link with automatic redirect based on client browser language 💥
14+
15+
## 🛠️ How to install
16+
### 🐳 Docker File
17+
```yml
18+
services:
19+
server:
20+
container_name: "picolink-server"
21+
image: ghcr.io/andreazorzi/picolink:latest
22+
restart: unless-stopped
23+
ports:
24+
- '80:80'
25+
environment:
26+
APP_ENV: 'production'
27+
APP_DEBUG: 'false'
28+
APP_URL: 'https://yourdomain.com'
29+
DB_DATABASE: 'laravel'
30+
DB_USERNAME: 'picolink'
31+
DB_PASSWORD: '_db_password_'
32+
33+
ADMIN_USERNAME: 'admin'
34+
ADMIN_PASSWORD: '_password_'
35+
networks:
36+
- sail
37+
depends_on:
38+
- mysql
39+
mysql:
40+
container_name: "picolink-db"
41+
image: 'mysql/mysql-server:8.0'
42+
restart: unless-stopped
43+
environment:
44+
MYSQL_ROOT_PASSWORD: '_root_password_'
45+
MYSQL_ROOT_HOST: '%'
46+
MYSQL_DATABASE: 'laravel'
47+
MYSQL_USER: 'picolink'
48+
MYSQL_PASSWORD: '_db_password_'
49+
volumes:
50+
- 'pathtodocker/picolink/mysql:/var/lib/mysql'
51+
networks:
52+
- sail
53+
networks:
54+
sail:
55+
driver: bridge
56+
```
57+
58+
59+
### 🎁 Additional .env configurations
60+
```yml
61+
# API Token
62+
API_TOKEN: _api_token_
63+
64+
# Authentik
65+
AUTHENTIK_BASE_URL: "https://auth.host.com"
66+
AUTHENTIK_CLIENT_ID: ""
67+
AUTHENTIK_CLIENT_SECRET: ""
68+
AUTHENTIK_REDIRECT_URI: "/auth/authentik/callback"
69+
AUTHENTIK_SLUG: "picolink"
70+
```
71+
72+
### 🤖 API Endpoint
73+
```json
74+
// Create multiple shorts
75+
// PUT /api/short/create
76+
// -H Authorization: Bearer _api_token_
77+
78+
// Data
79+
{
80+
"shorts": [
81+
{
82+
"code": "short1", // set null for generated code
83+
"description": "link to website",
84+
"url": "https://website.com/default-redirect-url",
85+
"languages": [
86+
{
87+
"language": "it",
88+
"url": "https://website.com/italian-redirect-url"
89+
},
90+
{
91+
"language": "de",
92+
"url": "https://website.com/german-redirect-url"
93+
},
94+
...
95+
],
96+
"tags": ["Tag1", "Tag2", "Tag3"]
97+
},
98+
...
99+
]
100+
}
101+
102+
// JSON Response
103+
{
104+
"status": "success", // or danger
105+
"message": "Short links created successfully.", // or the errors
106+
"shorts": [ // if success, get the shorted link
107+
"https://website.com/default-redirect-url": "https://short.com/short1"
108+
]
109+
}
110+
```

app/Classes/Help.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace App\Classes;
55

66
use Illuminate\Support\Str;
7-
7+
use Detection\MobileDetect;
88

99
class Help
1010
{
@@ -13,7 +13,7 @@ public static function convert_date(string $date):string{
1313
}
1414

1515
public static function fragment(string $view, string $fragment, array $data = []):string{
16-
return view($view, $data)->fragment($fragment);
16+
return view($view, array_merge($data, ["fragment" => true]))->fragment($fragment);
1717
}
1818

1919
public static function strToLen(?string $str, int $len, bool $left = false){
@@ -45,4 +45,35 @@ public static function empty_dictionary($dictionary){
4545

4646
return true;
4747
}
48+
49+
public static function preferred_language(){
50+
$browser_language = request()->getPreferredLanguage();
51+
52+
return explode("_", $browser_language)[0];
53+
}
54+
55+
public static function getRequestData(){
56+
// Browser language
57+
$browser_language = explode("_", request()->getPreferredLanguage())[0];
58+
59+
// Device type
60+
$detect = new MobileDetect;
61+
$device_type = "desktop";
62+
63+
if($detect->isMobile()){
64+
$device_type = $detect->isTablet() ? "tablet" : "mobile";
65+
}
66+
67+
// Referrer
68+
$referrer = request()->headers->get("referer");
69+
70+
$request_data = [
71+
"ip" => config('app.env') == 'local' ? fake()->ipv4() : $_SERVER["HTTP_X_FORWARDED_FOR"] ?? request()->ip(),
72+
"language" => $browser_language,
73+
"device_type" => $device_type,
74+
"referrer" => $referrer ? parse_url($referrer, PHP_URL_HOST) : "direct"
75+
];
76+
77+
return $request_data;
78+
}
4879
}

0 commit comments

Comments
 (0)