开源一个简单的短网址程序 Ourls

2015-09-20 17:21:10 +08:00
 takashiki

一直想要自己搭一个短网址服务,奈何 github 上找过几圈,都没有找到十分符合心意的,于是就趁周末自己写了一个。

Ourls 是一个基于发号加 hash id 实现的短址服务,灵感来源于知乎上关于短址生成算法的一个问题下的讨论,http://www.zhihu.com/question/29270034

详见:http://blog.skyx.in/archives/183/

在线演示地址:http://skyx.in/

github 地址:https://github.com/takashiki/Ourls

osc 地址:http://git.oschina.net/takashiki/Ourls

13334 次点击
所在节点    分享创造
33 条回复
Xrong
2015-09-20 17:29:52 +08:00
http://skyx.in/GRv7G 直接 500 错误了
hinate
2015-09-20 17:34:25 +08:00
Tink
2015-09-20 17:36:36 +08:00
正则也有问题,非 url 也能直接缩址
takashiki
2015-09-20 17:43:36 +08:00
@Xrong
@hinate url 里没带 http 吧
takashiki
2015-09-20 17:44:35 +08:00
@Tink 没写正则,正则以后可能考虑前端加一下,后端不加,这样就能用来编码其他信息了
popok
2015-09-20 17:56:16 +08:00
生成短地址按顺序编号,存入数据库,编号转换成 62 进制( 26 小写, 26 大写, 10 数字)。
还原长地址把 62 进制转 10 进制,进数据库按编号查长地址, 301 跳
popok
2015-09-20 17:57:28 +08:00
对了,上面是我的思路
takashiki
2015-09-20 18:00:20 +08:00
@popok hash 是为了防止被遍历
huangtao728
2015-09-20 19:12:27 +08:00
500 Internal Server Error

Missing argument 1 for {closure}(), called in /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php on line 160 and defined (2 )

#0 /data1/www/htdocs/518/ourls/1/app/routes.php (75 ): flight\Engine->handleError (2, 'Missing argumen...', '/data1/www/htdo...', 75, Array )
#1 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (160 ): {closure}()
#2 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (143 ): flight\core\Dispatcher::callFunction (Object (Closure ), Array )
#3 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (48 ): flight\core\Dispatcher::execute (Object (Closure ), Array )
#4 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/Engine.php (64 ): flight\core\Dispatcher->run ('notFound', Array )
#5 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/Engine.php (324 ): flight\Engine->__call ('notFound', Array )
#6 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/Engine.php (324 ): flight\Engine->notFound ()
#7 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (191 ): flight\Engine->_start ()
#8 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (142 ): flight\core\Dispatcher::invokeMethod (Array, Array )
#9 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (48 ): flight\core\Dispatcher::execute (Array, Array )
#10 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/Engine.php (64 ): flight\core\Dispatcher->run ('start', Array )
#11 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (191 ): flight\Engine->__call ('start', Array )
#12 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/core/Dispatcher.php (191 ): flight\Engine->start ()
#13 /data1/www/htdocs/518/ourls/1/vendor/mikecao/flight/flight/Flight.php (65 ): flight\core\Dispatcher::invokeMethod (Array, Array )
#14 /data1/www/htdocs/518/ourls/1/public/index.php (18 ): Flight::__callStatic ('start', Array )
#15 /data1/www/htdocs/518/ourls/1/public/index.php (18 ): Flight::start ()
#16 {main}

应该禁止缩短 skyx.in
404 页面也该改一改。
takashiki
2015-09-20 19:23:28 +08:00
@huangtao728 嗯,是的,刚刚改了, 500 我也改下
kfll
2015-09-20 19:38:17 +08:00
huangtao728
2015-09-20 19:45:41 +08:00
@takashiki
恩, 500 不再爆出错误了。
把我刚才创的短链接删掉吧,现在点击仍有循环跳转。
skyx.in/Vy3g2skyx.in/skyx.in/skyx.in
takashiki
2015-09-20 19:47:20 +08:00
sobigfish
2015-09-20 20:02:51 +08:00
哟,发现 bug 了
https://www.v2ex.com/t/222201#reply13
https://www.v2ex.com/t/222201#reply14
你说这 2 个 url 一样不呢?
takashiki
2015-09-20 20:06:00 +08:00
@sobigfish 不一样,我是直接取整个 url 的 sha1 值的
hinate
2015-09-20 21:56:02 +08:00
我那个短连是好了,但我当时是填的百度的地址,现在打开是不对的,难道当时我和一楼填的地址不一样生成的确实一样的?
takashiki
2015-09-20 22:03:26 +08:00
@hinate 你是啥时候生成的,我一开始发出来的时候不知道是有人刷还是爬虫刷,刷了接近一万条记录,我就把之前的全清掉了。
takashiki
2015-09-20 22:04:43 +08:00
@hinate 应该是因为我清掉一批之后 id 又从头开始了
GPU
2015-09-20 22:15:00 +08:00
昨天的 wwurl 很漂亮
takashiki
2015-09-20 22:33:11 +08:00
@GPU 我一般前端都用现成的框架

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/222201

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX