Skip to content

Commit 10bf24d

Browse files
committed
support Range header
1 parent 16cfdb0 commit 10bf24d

File tree

18 files changed

+220
-44
lines changed

18 files changed

+220
-44
lines changed

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1313
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
* GNU Affero General Public License for more details.
15-
*
15+
*
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/

cluster.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1313
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
* GNU Affero General Public License for more details.
15-
*
15+
*
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
@@ -52,10 +52,11 @@ type Cluster struct {
5252

5353
redirectBase string
5454

55-
cacheDir string
56-
tmpDir string
57-
dataDir string
58-
maxConn int
55+
cacheDir string
56+
tmpDir string
57+
dataDir string
58+
maxConn int
59+
ossSupportRange bool
5960

6061
stats Stats
6162
hits atomic.Int32

dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1313
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
* GNU Affero General Public License for more details.
15-
*
15+
*
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/

dashboard/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const langNameMap: { [key: string]: string } = {
2828
<Dropdown v-model="selectedLang" class="lang-selector"
2929
:options="languages" placeholder="Language">
3030
<template #value="slotProps">
31-
<span class="flex-row-center">
31+
<span class="flex-row-center" style="margin-right: -0.75rem;">
3232
<i class="pi pi-globe"></i>
3333
{{ langNameMap[slotProps.value.toString()] }}
3434
</span>

dashboard/src/assets/lang/en-US.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"lang": "English",
33
"title": {
4-
"dashboard": "Dashboard"
4+
"dashboard": "Dashboard",
5+
"day": "Day requests",
6+
"month": "Month requests",
7+
"year": "Year requests",
8+
"total": "Total requests"
59
},
610
"message": {
711
"server": {

dashboard/src/assets/lang/zh-CN.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"lang": "简体中文",
33
"title": {
4-
"dashboard": "仪表盘"
4+
"dashboard": "仪表盘",
5+
"day": "日请求",
6+
"month": "月请求",
7+
"year": "年请求",
8+
"total": "全部请求"
59
},
610
"message": {
711
"server": {

dashboard/src/views/HomeView.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function getDaysInMonth(): number {
115115
</div>
116116
</div>
117117
<div class="chart-card">
118-
<h3>Day</h3>
118+
<h3>{{ tr('title.day') }}</h3>
119119
<HitsChart
120120
v-if="data && stat"
121121
class="hits-chart"
@@ -129,7 +129,7 @@ function getDaysInMonth(): number {
129129
<Skeleton v-else class="hits-chart"/>
130130
</div>
131131
<div class="chart-card">
132-
<h3>Month</h3>
132+
<h3>{{ tr('title.month') }}</h3>
133133
<HitsChart
134134
v-if="data && stat"
135135
class="hits-chart"
@@ -143,12 +143,12 @@ function getDaysInMonth(): number {
143143
<Skeleton v-else class="hits-chart"/>
144144
</div>
145145
<div class="chart-card">
146-
<h3>Year</h3>
146+
<h3><h3>{{ tr('title.year') }}</h3></h3>
147147
<HitsChart
148148
v-if="data && stat"
149149
class="hits-chart"
150-
:max="14"
151-
:offset="12"
150+
:max="13"
151+
:offset="11"
152152
:data="stat.months"
153153
:oldData="stat.prev.months"
154154
:current="stat.date.month + getDaysInMonth()"
@@ -242,6 +242,7 @@ function getDaysInMonth(): number {
242242
.hits-chart {
243243
width: 45rem !important;
244244
height: 13rem !important;
245+
user-select: none;
245246
}
246247
247248
@media (max-width: 48rem) {

handler.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1313
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
* GNU Affero General Public License for more details.
15-
*
15+
*
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
@@ -28,6 +28,8 @@ import (
2828
"strconv"
2929
"strings"
3030
"time"
31+
32+
"github.com/LiterMC/go-openbmclapi/internal/gosrc"
3133
)
3234

3335
var zeroBuffer [1024 * 1024]byte
@@ -128,17 +130,31 @@ func (cr *Cluster) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
128130
}
129131
}
130132
name := req.Form.Get("name")
133+
134+
// if use OSS redirect
131135
if cr.redirectBase != "" {
132136
target, err := url.JoinPath(cr.redirectBase, "download", hashToFilename(hash))
133137
if err != nil {
134138
http.Error(rw, err.Error(), http.StatusInternalServerError)
135139
return
136140
}
141+
size := stat.Size()
142+
if cr.ossSupportRange { // fix the size for Ranged request
143+
rg := req.Header.Get("Range")
144+
rgs, err := gosrc.ParseRange(rg, size)
145+
if err == nil {
146+
size = 0
147+
for _, r := range rgs {
148+
size += r.Length
149+
}
150+
}
151+
}
137152
http.Redirect(rw, req, target, http.StatusFound)
138153
cr.hits.Add(1)
139-
cr.hbts.Add(stat.Size())
154+
cr.hbts.Add(size)
140155
return
141156
}
157+
142158
rw.Header().Set("Cache-Control", "max-age=2592000") // 30 days
143159
fd, err := os.Open(path)
144160
if err != nil {

hijacker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1313
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
* GNU Affero General Public License for more details.
15-
*
15+
*
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/

internal/gosrc/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2009 The Go Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)