The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
freestyle

用 golang 撸了个文件中转服务

  •  1
     
  •   freestyle ·
    hanjm · Feb 9, 2017 · 5023 views
    This topic created in 3556 days ago, the information mentioned may be changed or developed.

    用于放 VPS 上中转文件, go 单文件, 部署无第三方依赖. 用 curl -IL 仅获取 Header 得到下载文件长度, 调用 wget 下载, 前端页面计算实现进度环, 这个进度环弄了挺久.

    若配合 kcptun( https://www.v2ex.com/t/297296 https://github.com/xtaci/kcptun), 拖回本地的速度可以飞起来

    Demo http://23.83.230.242/file_download_proxy/

    Source https://github.com/hanjm/file_download_proxy

    http://ww1.sinaimg.cn/large/cfe1407cgy1fckgltj5vrj21dl0g2wh1.jpg

    Supplement 1  ·  Feb 10, 2017
    v2exer 发现了可以 xss 忘记转义了 受教
    Supplement 2  ·  Feb 10, 2017
    replace("</", "<\\/")
    Supplement 3  ·  Feb 10, 2017
    由于有 cache, 用户下载时文件被删除没有影响的
    Supplement 4  ·  Feb 12, 2017
    update:支持磁力链接(via aria2 jsonrpc interface)
    Supplement 5  ·  Mar 18, 2017
    2017-03-17 更新,使用 websocket 实现仅当有任务在下载时推送文件状态更新,代替原来消耗过大的 ajax 轮询.
    Supplement 6  ·  Mar 18, 2017
    由于使用了 websocket 依赖包 github.com/gorilla/websocket
    Supplement 7  ·  Mar 22, 2017
    2017-03 改进: 文件下载函数复用 Goroutines,代替原来的直接 go func 使用 http.Client 代替 curl wget (笑 cry
    44 replies  •  2017-03-18 00:03:58 +08:00
    freestyle
    freestyle
    OP
    Feb 9, 2017
    1
    图挂了?
    freestyle
    freestyle
    OP
    Feb 10, 2017
    2
    服务器收到一大堆大文件 TestFile,然后塞满了.....
    v2ex 真厉害

    2017/02/09 10:58:30 Download: length:9.77 GB source:http://speed.hetzner.de/10GB.bin filename:10GB-1486655910.bin
    bl5c
    bl5c
    Feb 10, 2017
    3
    不是有现成的 rapidleech
    你这个可以加个密码登录
    nfroot
    nfroot
    Feb 10, 2017
    4
    下载 URL 无文件名的网址没有“下载地址”(下载后)

    比如你下载“ http://23.83.230.242/file_download_proxy/”这个网址试试,下载地址那一栏是空的
    hillw4h
    hillw4h
    Feb 10, 2017
    5
    我去,被人 xss 了。
    nfroot
    nfroot
    Feb 10, 2017
    6
    某些人也是病态,丢了一堆 10G 大小的文件的链接上去。
    relaxchen
    relaxchen
    Feb 10, 2017
    7
    @nfroot 明显的素质问题
    weiweiwitch
    weiweiwitch
    Feb 10, 2017
    8
    先给你加个 Star 。
    freestyle
    freestyle
    OP
    Feb 10, 2017
    9
    @nfroot 谢谢. 发现是前端显示判断有问题
    nfroot
    nfroot
    Feb 10, 2017
    10
    @freestyle 增加一个限制文件大小的选项吧 要不然那些病态的人会老是去尝试做一些病态的事情
    nfroot
    nfroot
    Feb 10, 2017
    11
    其实以前还是蛮想要个这东西的,如果有 PHP 的就好了,不过调用 exe 文件实在是……
    freestyle
    freestyle
    OP
    Feb 10, 2017
    12
    @nfroot 好 Content-Length < 3G
    freestyle
    freestyle
    OP
    Feb 10, 2017
    13
    @nfroot 也可以让 go 去请求文件 但是要处理 30X
    vultr
    vultr
    Feb 10, 2017
    14
    速度还真快,谢谢。下了个 freebsd
    deweixu
    deweixu
    Feb 10, 2017
    15
    正好最近在学 go , star
    nfroot
    nfroot
    Feb 10, 2017
    16
    @freestyle 咦,楼主你这个是搬瓦工的 FREMONT 节点啊?翻墙效果咋样,电信。
    freestyle
    freestyle
    OP
    Feb 10, 2017
    17
    @nfroot 是的 ss 速度不快 一两百 KB/s 用 kcptun 转后就不错了,youtube 可 HD
    ptyfork
    ptyfork
    Feb 10, 2017
    18
    xss 在哪里?
    ptyfork
    ptyfork
    Feb 10, 2017
    19
    不支持磁链啊
    iyaozhen
    iyaozhen
    Feb 10, 2017
    20
    之前也自己搞了个 download.sh ,下载后放在 Nginx 下,开迅雷下载速度也是飞起,不过没有实现前端页面。
    J0022ZjV7055oN64
    J0022ZjV7055oN64
    Feb 10, 2017
    21
    正好需要这个 thx
    yuchenr
    yuchenr
    Feb 10, 2017
    22
    感觉要被玩坏
    yghack
    yghack
    Feb 10, 2017
    23
    赞一个!
    nfroot
    nfroot
    Feb 10, 2017
    24
    @freestyle 奇怪,国内一般不是推荐 LOS ANGELES 的节点么 0 0
    loading
    loading
    Feb 10, 2017 via Android
    25
    不加密码不敢装到自己 vps ……

    楼主有考虑支持其他类型吗? bt 和磁力
    freestyle
    freestyle
    OP
    Feb 10, 2017 via iPhone
    26
    @loading 自用的话搞个长点的 token 就行了 好,加
    yghack
    yghack
    Feb 10, 2017
    27
    不是了一下,竟然是 404
    什么问题?
    mcfog
    mcfog
    Feb 10, 2017
    28
    ……乞丐版 aria2 ?
    huixia0010
    huixia0010
    Feb 10, 2017
    29
    受教了
    ptyfork
    ptyfork
    Feb 10, 2017
    30
    磁链我觉得可以调用 transmission 来下载
    xJogger
    xJogger
    Feb 10, 2017 via Android❤️2
    31
    @ptyfork Cloud Torrent 不错。
    ptyfork
    ptyfork
    Feb 10, 2017
    32
    @xJogger

    大赞啊, 感谢已发送!

    Go 的库确实越来越丰富了,我以为没有 torrent 的库呢。。

    github.com/anacrolix/torrent
    freestyle
    freestyle
    OP
    Feb 10, 2017
    33
    @xJogger 感谢,这个不错
    claysec
    claysec
    Feb 10, 2017
    34
    现在支持 torrent 吗?
    freestyle
    freestyle
    OP
    Feb 10, 2017
    35
    gopher://120.27.202.184:32/1.php 是什么姿势
    freestyle
    freestyle
    OP
    Feb 10, 2017
    36
    @claysec
    不支持, 看 @xJogger 提到的 https://github.com/jpillora/cloud-torrent, 试了下, 功能非常全
    lhbc
    lhbc
    Feb 10, 2017
    37
    这个需求,用 nginx 的反代是最合适的。
    而且,不占用服务器空间。
    dreammes
    dreammes
    Feb 10, 2017
    38
    姿势不错哦
    nicoljiang
    nicoljiang
    Feb 11, 2017 via iPhone
    39
    mark
    freestyle
    freestyle
    OP
    Feb 11, 2017
    40
    @claysec
    @ptyfork
    @xJogger 用 vps 下载磁链 /torrent 可能不小心下到了受版权保护的资源, 我正测试加磁链的功能, 下了个降临, 然后第一次收到了 DCMA complaint
    xJogger
    xJogger
    Feb 11, 2017 via Android
    41
    @freestyle 我一般在 Daocloud 提供的测试容器上用 Cloud Torrent …虽然只能挂一天,不过小资源也够用了。
    roist
    roist
    Feb 11, 2017
    42
    Absolutely fantastic
    freestyle
    freestyle
    OP
    Feb 12, 2017 via iPhone❤️2
    43
    @claysec
    @loading 支持磁力了
    freestyle
    freestyle
    OP
    Mar 18, 2017
    44
    2017-03-17 更新,使用 websocket 实现仅当有任务在下载时推送文件状态更新,代替原来消耗过大的 ajax 轮询.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1412 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 74ms · UTC 19:06 · PVG 03:06 · LAX 11:06 · JFK 14:06
    ♥ Do have faith in what you're doing.