tinyurl
v1.0.7
Tinyurl เป็นตัวย่อ URL ที่เรียบง่ายสร้างบน Java Project Is Open Source (Apache License, Version 2.0)
# SystemProperty / Default value
org.javastack.tinyurl.config=[classpath]/org.javastack.tinyurl.properties
file:///etc/tinyurl/org.javastack.tinyurl.properties
หรือ https://config-server/tinyurl/org.javastack.tinyurl.properties
# Parameter / Default value
storage.dir=[webapp]/WEB-INF/storage/
whitelist.file=file://[storage.dir]/whitelist.conf
check.flags=WHITELIST,CONNECTION
check.cache.millis=60000
connection.timeout.millis=10000
read.timeout.millis=30000
dump.key=[random]
#
# Default KVStore Persistence
storage.class=org.javastack.tinyurl.PersistentKVStore
#
# Optional MySQL Persistence (default: not enabled)
#storage.class=org.javastack.tinyurl.jdbc.PersistentMySQL
#storage.url=jdbc:mysql://localhost:3306/tinyurl
#storage.username=tinyurl
#storage.password=secret
#
# QR Codes
#base.url=https://tiny.javastack.org/r/
#qr.size.min=50
#qr.size.max=1000
#qr.size.default=300
org.javastack.tinyurl.PersistentKVStore
: Kvstore Stervantence (ค่าเริ่มต้น, พกพา)org.javastack.tinyurl.jdbc.PersistentMySQL
: การคงอยู่ของ MySQLexample: https://tiny.javastack.org/r/
CATALINA_OPTS="-Dorg.javastack.tinyurl.config=file://${CATALINA_BASE}/conf/org.javastack.tinyurl.properties"
ใน Tomcat/bin/setenv.sh (Linux)GRANT ALL ON tinyurl.* TO 'tinyurl'@'%' IDENTIFIED BY 'secret';
API สำหรับการตัดทอนนั้นง่ายมาก:
# Method: POST
# Path: /tiny
# Content-Type: application/x-www-form-urlencoded
# Parameter: "url=${longURLencoded}"
# Example: curl -i -d "url=https%3A%2F%2Fgithub.com%2Fggrandes%2Ftinyurl%2F" ${BASE_URL}/tiny
ส่งคืนสิ่งนี้:
HTTP/1.1 200 OK
Content-Type: application/json;charset=ISO-8859-1
Content-Length: 19
Cache-control: must-revalidate, max-age=0
{ "id": "iN8diz" }
# Method: GET
# Path: /q/{id}
# Example: curl -i ${BASE_URL}/q/iN8diz
ส่งคืนสิ่งนี้:
HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/png
Content-Length: 475
.PNG...binary-data...
# Method: GET
# Path: /r/{id}
# Example: curl -i ${BASE_URL}/r/iN8diz
ส่งคืนสิ่งนี้:
HTTP/1.1 302 Found
Location: https://github.com/ggrandes/tinyurl/
Content-Length: 0
Cache-control: must-revalidate, max-age=0
ค่า hardcoded ปัจจุบัน:
KEY_SPACE
คือ: 6 อักขระ (base64 คือ 64^ks (6) = 68.719.476.736 ปุ่มสูงสุด)แรงบันดาลใจใน goo.gl, bit.ly และ cort.as รหัสนี้เป็นเวอร์ชัน java-minimalistic