Skip to content

Commit

Permalink
Merge pull request #383 from LamGC/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol authored Jun 22, 2023
2 parents b8f666d + 0c52fcd commit b6b7396
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/docs/development/SC/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ Current map background image

* Base url with no parameters returns map image file as-is without any processing.
* setting `width` or `height` query parameters ensures that at least one of these will be matched while preserving original image aspect ratio. [check it out](http://localhost:20727/backgroundImage?width=500&height=500)
* in addition, setting `crop=1` disregards image aspect ratio and returns cropped image with specified dimensions, resizing it beforehand if necessary. [check it out](http://localhost:20727/backgroundImage?width=500&height=500&crop=1)
* in addition, setting `crop=true` disregards image aspect ratio and returns cropped image with specified dimensions, resizing it beforehand if necessary. [check it out](http://localhost:20727/backgroundImage?width=500&height=500&crop=true)
* Set `cache=true` and SC will set the [**Cache-Control**](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control) response header to instruct the browser to cache background images. When images are repeatedly loaded, it will save a lot of loading time.
::: tip cache usage
When using caching, it is necessary to add some query parameters to distinguish requests. If no other parameters are added, it will result in your browser always reusing the background image of the first loaded map. For example, you can use Id of the current map to create unique urls:

`/backgroundImage?cache=true&mapId=123456`
:::

### [`Songs`](http://localhost:20727/Songs)

Expand Down
4 changes: 4 additions & 0 deletions plugins/WebSocketDataSender/WebSocketDataGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ private async Task SendCurrentBeatmapImage(IHttpContext context)
if (!File.Exists(location))
return;

bool.TryParse(context.Request.QueryString.Get("cache"), out var enableCache);
if (enableCache)
context.Response.Headers.Add("Cache-Control", "public, max-age=7200");

await using var fs = new FileStream(location, FileMode.Open, FileAccess.Read);
if (!(context.Request.QueryString.ContainsKey("width") ||
context.Request.QueryString.ContainsKey("height")))
Expand Down

0 comments on commit b6b7396

Please sign in to comment.