forked from FreeTubeApp/FreeTube
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream_development' into development
# Conflicts: # src/renderer/store/modules/utils.js # yarn.lock
- Loading branch information
Showing
40 changed files
with
972 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,22 +77,22 @@ jobs: | |
date +"%Y-%m-%d" >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
- name: Update x64 File Location in yml File | ||
uses: mikefarah/[email protected].1 | ||
uses: mikefarah/[email protected].2 | ||
with: | ||
# The Command which should be run | ||
cmd: yq w -i io.freetubeapp.FreeTube.yml modules[0].sources[0].url 'https://github.com/FreeTubeApp/FreeTube/releases/download/v${{ steps.sub.outputs.result }}-beta/freetube-${{ steps.sub.outputs.result }}-linux-portable-x64.zip' | ||
- name: Update x64 Hash in yml File | ||
uses: mikefarah/[email protected].1 | ||
uses: mikefarah/[email protected].2 | ||
with: | ||
# The Command which should be run | ||
cmd: yq w -i io.freetubeapp.FreeTube.yml modules[0].sources[0].sha256 ${{ env.HASH_X64 }} | ||
- name: Update ARM File Location in yml File | ||
uses: mikefarah/[email protected].1 | ||
uses: mikefarah/[email protected].2 | ||
with: | ||
# The Command which should be run | ||
cmd: yq w -i io.freetubeapp.FreeTube.yml modules[0].sources[1].url 'https://github.com/FreeTubeApp/FreeTube/releases/download/v${{ steps.sub.outputs.result }}-beta/freetube-${{ steps.sub.outputs.result }}-linux-portable-arm64.zip' | ||
- name: Update ARM Hash in yml File | ||
uses: mikefarah/[email protected].1 | ||
uses: mikefarah/[email protected].2 | ||
with: | ||
# The Command which should be run | ||
cmd: yq w -i io.freetubeapp.FreeTube.yml modules[0].sources[1].sha256 ${{ env.HASH_ARM64 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ jobs: | |
|
||
# For bug reports | ||
- name: New bug issue | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: contains(github.event.issue.labels.*.name, 'bug') && github.event.action == 'opened' | ||
with: | ||
project: Bug Reports | ||
|
@@ -22,7 +22,7 @@ jobs: | |
action: update | ||
|
||
- name: Bug issue closed | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: github.event.action == 'closed' || github.event.action == 'deleted' | ||
with: | ||
action: delete | ||
|
@@ -31,7 +31,7 @@ jobs: | |
repo-token: ${{ secrets.PUSH_TOKEN }} | ||
|
||
- name: Bug issue reopened | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: contains(github.event.issue.labels.*.name, 'bug') && github.event.action == 'reopened' | ||
with: | ||
project: Bug Reports | ||
|
@@ -41,7 +41,7 @@ jobs: | |
|
||
# For feature requests | ||
- name: New feature issue | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: contains(github.event.issue.labels.*.name, 'enhancement') && github.event.action == 'opened' | ||
with: | ||
project: Feature Requests | ||
|
@@ -50,7 +50,7 @@ jobs: | |
action: update | ||
|
||
- name: Feature request issue closed | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: github.event.action == 'closed' || github.event.action == 'deleted' | ||
with: | ||
action: delete | ||
|
@@ -59,7 +59,7 @@ jobs: | |
repo-token: ${{ secrets.PUSH_TOKEN }} | ||
|
||
- name: Feature request issue reopened | ||
uses: alex-page/[email protected].1 | ||
uses: alex-page/[email protected].2 | ||
if: contains(github.event.issue.labels.*.name, 'enhancement') && github.event.action == 'reopened' | ||
with: | ||
project: Feature Requests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// cleanup expired images once every 5 mins | ||
const CLEANUP_INTERVAL = 300_000 | ||
|
||
// images expire after 2 hours if no expiry information is found in the http headers | ||
const FALLBACK_MAX_AGE = 7200 | ||
|
||
export class ImageCache { | ||
constructor() { | ||
this._cache = new Map() | ||
|
||
setInterval(this._cleanup.bind(this), CLEANUP_INTERVAL) | ||
} | ||
|
||
add(url, mimeType, data, expiry) { | ||
this._cache.set(url, { mimeType, data, expiry }) | ||
} | ||
|
||
has(url) { | ||
return this._cache.has(url) | ||
} | ||
|
||
get(url) { | ||
const entry = this._cache.get(url) | ||
|
||
if (!entry) { | ||
// this should never happen as the `has` method should be used to check for the existence first | ||
throw new Error(`No image cache entry for ${url}`) | ||
} | ||
|
||
return { | ||
data: entry.data, | ||
mimeType: entry.mimeType | ||
} | ||
} | ||
|
||
_cleanup() { | ||
// seconds since 1970-01-01 00:00:00 | ||
const now = Math.trunc(Date.now() / 1000) | ||
|
||
for (const [key, entry] of this._cache.entries()) { | ||
if (entry.expiry <= now) { | ||
this._cache.delete(key) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Extracts the cache expiry timestamp of image from HTTP headers | ||
* @param {Record<string, string>} headers | ||
* @returns a timestamp in seconds | ||
*/ | ||
export function extractExpiryTimestamp(headers) { | ||
const maxAgeRegex = /max-age=([0-9]+)/ | ||
|
||
const cacheControl = headers['cache-control'] | ||
if (cacheControl && maxAgeRegex.test(cacheControl)) { | ||
let maxAge = parseInt(cacheControl.match(maxAgeRegex)[1]) | ||
|
||
if (headers.age) { | ||
maxAge -= parseInt(headers.age) | ||
} | ||
|
||
// we don't need millisecond precision, so we can store it as seconds to use less memory | ||
return Math.trunc(Date.now() / 1000) + maxAge | ||
} else if (headers.expires) { | ||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires | ||
|
||
return Math.trunc(Date.parse(headers.expires) / 1000) | ||
} else { | ||
return Math.trunc(Date.now() / 1000) + FALLBACK_MAX_AGE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.