Skip to content

Commit

Permalink
Merge branch 'main' into feature/local-dash
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Oct 14, 2023
2 parents cab1f7f + fc3629d commit bb18288
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Layout in channel view so that the upload time and view count of videos is visible

### Changed

- Cache format so it does less parsing work

## [0.13.1] - 2023-10-08

### Added
Expand Down
23 changes: 16 additions & 7 deletions playlet-lib/src/components/ChannelView/ChannelView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "pkg:/source/utils/Types.bs"
function Init()
m.container = m.top.findNode("container")
m.scrollAnimation = m.top.findNode("scrollAnimation")
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
m.containerTranslation = m.scrollAnimation.findNode("containerTranslation")
m.bannerTranslation = m.scrollAnimation.findNode("bannerTranslation")

m.banner = m.top.findNode("banner")
m.thumbnail = m.top.findNode("thumbnail")
Expand Down Expand Up @@ -95,16 +96,24 @@ function OnBannerLoadStatus() as void
return
end if

aspect = m.banner.bitmapWidth / m.banner.bitmapHeight
m.banner.height = m.banner.width / aspect
m.banner.translation = [0, -m.banner.height]
bannerAspect = m.banner.bitmapWidth / m.banner.bitmapHeight
bannerHeight = m.banner.width / bannerAspect
m.banner.height = bannerHeight
m.banner.translation = [0, -bannerHeight]
m.banner.visible = true

startPos = [0, -bannerHeight]
endPos = [0, 0]
midPos = [0, (startPos[1] + endPos[1]) / 2]

m.bannerTranslation.keyValue = [startPos, midPos, endPos]

startPos = [0, 0]
endPos = [0, m.banner.height]
midPos = [0, m.banner.height / 2]
endPos = [0, bannerHeight - m.thumbnail.height * 0.4]
midPos = [0, (startPos[1] + endPos[1]) / 2]

m.containerTranslation.keyValue = [startPos, midPos, endPos]

m.scrollAnimationInterpolator.keyValue = [startPos, midPos, endPos]
m.scrollAnimation.control = "start"
end function

Expand Down
16 changes: 10 additions & 6 deletions playlet-lib/src/components/ChannelView/ChannelView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
color="0x242424">
</Rectangle>

<Group id="container">
<Poster
id="banner"
width="1280"
visible="false" />
<Poster
id="banner"
width="1280"
visible="false" />

<Group id="container">
<Poster
translation="[115,20]"
width="104"
Expand Down Expand Up @@ -58,7 +58,11 @@
delay="0.3"
duration="0.6">
<Vector2DFieldInterpolator
id="scrollAnimationInterpolator"
id="bannerTranslation"
key="[ 0.0, 0.5, 1.0 ]"
fieldToInterp="banner.translation" />
<Vector2DFieldInterpolator
id="containerTranslation"
key="[ 0.0, 0.5, 1.0 ]"
fieldToInterp="container.translation" />
</Animation>
Expand Down
71 changes: 58 additions & 13 deletions playlet-lib/src/source/services/HttpClient.bs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ namespace HttpClientCache
end if

hash = CryptoUtils.GetMd5(cacheKey)
request._cacheLocation = `cachefs:/request_v1_${hash}.json`
request._cacheLocation = `cachefs:/request_v2_${hash}.json`
return request._cacheLocation
end function

Expand Down Expand Up @@ -590,16 +590,37 @@ namespace HttpClientCache

cacheLocation = GetLocation(request)
cacheText = ReadAsciiFile(cacheLocation)
cacheObject = ParseJson(cacheText)
if cacheObject = invalid
if cacheText = invalid
return invalid
end if

firstLineIndex = cacheText.InStr(`\n`)
if firstLineIndex = -1
LogWarn("Failed to parse cache.")
Delete(request)
return invalid
end if

metadataText = cacheText.Left(firstLineIndex)
metadata = ParseJson(metadataText)
if metadata = invalid
LogWarn("Failed to parse metadata from cache.")
Delete(request)
return invalid
end if

headersText = cacheText.Mid(firstLineIndex + 1, metadata.headers)
headers = ParseJson(headersText)
if headers = invalid
LogWarn("Failed to parse headers from cache.")
Delete(request)
return invalid
end if

expireSeconds = request._expireSeconds

if expireSeconds = invalid and cacheObject.headers <> invalid
expireSeconds = ParseHeadersForCacheControl(cacheObject.headers)
if expireSeconds = invalid and headers <> invalid
expireSeconds = ParseHeadersForCacheControl(headers)
end if

if expireSeconds = invalid
Expand All @@ -608,12 +629,21 @@ namespace HttpClientCache

date = CreateObject("roDateTime")
nowTimestamp = date.AsSeconds()
if cacheObject.timestamp + expireSeconds < nowTimestamp
if metadata.timestamp + expireSeconds < nowTimestamp
Delete(request)
return invalid
end if

return cacheObject
body = ""
if metadata.body > 0
body = cacheText.Mid(firstLineIndex + 1 + metadata.headers, metadata.body)
end if

return {
statusCode: metadata.statusCode,
headers: headers,
body: body
}
end function

function Set(response as HttpClient.HttpResponse) as void
Expand Down Expand Up @@ -643,17 +673,32 @@ namespace HttpClientCache
date = CreateObject("roDateTime")
timestamp = date.AsSeconds()

cacheObject = {
' Cache file format:
' First line is a json payload of metadata:
' {
' timestamp: number,
' statusCode: number,
' headers: number, ' this is the size of the headers json array in chars
' body: number ' this is the size of the body in chars
' }
' {headers} ' a json objects with headers, string size matching metadata.headers
' {body} ' the body as is, string size matching metadata.body

jsonHeaders = FormatJson(response.Headers())
body = ValidString(response.Text())

cacheMetadata = {
timestamp: timestamp,
statusCode: response.StatusCode(),
headers: response.Headers(),
body: response.Text()
headers: jsonHeaders.Len(),
body: body.Len()
}

jsonMetadata = FormatJson(cacheMetadata)

cacheLocation = GetLocation(response.request)
' TODO:P2 use a diferent format other than json for better performance
cacheText = FormatJson(cacheObject)
WriteAsciiFile(cacheLocation, cacheText)

WriteAsciiFile(cacheLocation, jsonMetadata + `\n` + jsonHeaders + body)
end function

function Delete(request as HttpClient.HttpRequest) as boolean
Expand Down

0 comments on commit bb18288

Please sign in to comment.