Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into hailey/dialogs-pt1
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Oct 4, 2024
2 parents 2d13212 + 09caf32 commit 992a5e8
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 78 deletions.
10 changes: 2 additions & 8 deletions bskyweb/cmd/bskyweb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,8 @@ func serve(cctx *cli.Context) error {
path := c.Request().URL.Path
maxAge := 1 * (60 * 60) // default is 1 hour

// Cache javascript and images files for 1 week, which works because
// they're always versioned (e.g. /static/js/main.64c14927.js)
if strings.HasPrefix(path, "/static/js/") || strings.HasPrefix(path, "/static/images/") || strings.HasPrefix(path, "/static/media/") {
maxAge = 7 * (60 * 60 * 24) // 1 week
}

// fonts can be cached for a year
if strings.HasSuffix(path, ".otf") {
// all assets in /static/js, /static/css, /static/media are content-hashed and can be cached for a long time
if strings.HasPrefix(path, "/static/js/") || strings.HasPrefix(path, "/static/css/") || strings.HasPrefix(path, "/static/media/") {
maxAge = 365 * (60 * 60 * 24) // 1 year
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"icons:optimize": "svgo -f ./assets/icons"
},
"dependencies": {
"@atproto/api": "^0.13.8",
"@atproto/api": "^0.13.11",
"@braintree/sanitize-url": "^6.0.2",
"@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",
"@emoji-mart/react": "^1.1.1",
Expand Down
32 changes: 15 additions & 17 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
AppBskyEmbedDefs,
AppBskyEmbedExternal,
AppBskyEmbedImages,
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedVideo,
AppBskyFeedPostgate,
AtUri,
BlobRef,
BskyAgent,
ComAtprotoLabelDefs,
RichText,
Expand Down Expand Up @@ -46,14 +44,7 @@ interface PostOpts {
uri: string
cid: string
}
video?: {
blobRef: BlobRef
altText: string
captions: {lang: string; file: File}[]
aspectRatio?: AppBskyEmbedDefs.AspectRatio
}
extLink?: ExternalEmbedDraft
images?: ComposerImage[]
labels?: string[]
threadgate: ThreadgateAllowUISetting[]
postgate: AppBskyFeedPostgate.Record
Expand Down Expand Up @@ -230,13 +221,15 @@ async function resolveMedia(
| AppBskyEmbedVideo.Main
| undefined
> {
if (opts.images?.length) {
const state = opts.composerState
const media = state.embed.media
if (media?.type === 'images') {
logger.debug(`Uploading images`, {
count: opts.images.length,
count: media.images.length,
})
opts.onStateChange?.(`Uploading images...`)
const images: AppBskyEmbedImages.Image[] = await Promise.all(
opts.images.map(async (image, i) => {
media.images.map(async (image, i) => {
logger.debug(`Compressing image #${i}`)
const {path, width, height, mime} = await compressImage(image)
logger.debug(`Uploading image #${i}`)
Expand All @@ -253,9 +246,10 @@ async function resolveMedia(
images,
}
}
if (opts.video) {
if (media?.type === 'video' && media.video.status === 'done') {
const video = media.video
const captions = await Promise.all(
opts.video.captions
video.captions
.filter(caption => caption.lang !== '')
.map(async caption => {
const {data} = await agent.uploadBlob(caption.file, {
Expand All @@ -266,13 +260,17 @@ async function resolveMedia(
)
return {
$type: 'app.bsky.embed.video',
video: opts.video.blobRef,
alt: opts.video.altText || undefined,
video: video.pendingPublish.blobRef,
alt: video.altText || undefined,
captions: captions.length === 0 ? undefined : captions,
aspectRatio: opts.video.aspectRatio,
aspectRatio: {
width: video.asset.width,
height: video.asset.height,
},
}
}
if (opts.extLink) {
// TODO: Read this from composer state as well.
if (opts.extLink.embed) {
return undefined
}
Expand Down
64 changes: 38 additions & 26 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,10 @@ export const ComposePost = ({
initQuote,
)

const [videoAltText, setVideoAltText] = useState('')
const [captions, setCaptions] = useState<{lang: string; file: File}[]>([])

// TODO: Move more state here.
const [composerState, dispatch] = useReducer(
composerReducer,
{initImageUris},
{initImageUris, initQuoteUri: initQuote?.uri},
createComposerState,
)

Expand Down Expand Up @@ -340,6 +337,7 @@ export const ComposePost = ({

const onNewLink = useCallback(
(uri: string) => {
dispatch({type: 'embed_add_uri', uri})
if (extLink != null) return
setExtLink({uri, isLoading: true})
},
Expand Down Expand Up @@ -424,29 +422,16 @@ export const ComposePost = ({
try {
postUri = (
await apilib.post(agent, {
composerState, // TODO: not used yet.
composerState, // TODO: move more state here.
rawText: richtext.text,
replyTo: replyTo?.uri,
images,
quote,
extLink,
labels,
threadgate: threadgateAllowUISettings,
postgate,
onStateChange: setProcessingState,
langs: toPostLanguages(langPrefs.postLanguage),
video:
videoState.status === 'done'
? {
blobRef: videoState.pendingPublish.blobRef,
altText: videoAltText,
captions: captions,
aspectRatio: {
width: videoState.asset.width,
height: videoState.asset.height,
},
}
: undefined,
})
).uri
try {
Expand Down Expand Up @@ -524,7 +509,6 @@ export const ComposePost = ({
[
_,
agent,
captions,
composerState,
extLink,
images,
Expand All @@ -543,9 +527,7 @@ export const ComposePost = ({
setExtLink,
setLangPrefs,
threadgateAllowUISettings,
videoAltText,
videoState.asset,
videoState.pendingPublish,
videoState.status,
],
)
Expand Down Expand Up @@ -585,6 +567,7 @@ export const ComposePost = ({

const onSelectGif = useCallback(
(gif: Gif) => {
dispatch({type: 'embed_add_gif', gif})
setExtLink({
uri: `${gif.media_formats.gif.url}?hh=${gif.media_formats.gif.dims[1]}&ww=${gif.media_formats.gif.dims[0]}`,
isLoading: true,
Expand All @@ -603,6 +586,7 @@ export const ComposePost = ({

const handleChangeGifAltText = useCallback(
(altText: string) => {
dispatch({type: 'embed_update_gif', alt: altText})
setExtLink(ext =>
ext && ext.meta
? {
Expand Down Expand Up @@ -783,6 +767,11 @@ export const ComposePost = ({
link={extLink}
gif={extGif}
onRemove={() => {
if (extGif) {
dispatch({type: 'embed_remove_gif'})
} else {
dispatch({type: 'embed_remove_link'})
}
setExtLink(undefined)
setExtGif(undefined)
}}
Expand Down Expand Up @@ -817,10 +806,28 @@ export const ComposePost = ({
/>
) : null)}
<SubtitleDialogBtn
defaultAltText={videoAltText}
saveAltText={setVideoAltText}
captions={captions}
setCaptions={setCaptions}
defaultAltText={videoState.altText}
saveAltText={altText =>
dispatch({
type: 'embed_update_video',
videoAction: {
type: 'update_alt_text',
altText,
signal: videoState.abortController.signal,
},
})
}
captions={videoState.captions}
setCaptions={updater => {
dispatch({
type: 'embed_update_video',
videoAction: {
type: 'update_captions',
updater,
signal: videoState.abortController.signal,
},
})
}}
Portal={Portal.Portal}
/>
</Animated.View>
Expand All @@ -833,7 +840,12 @@ export const ComposePost = ({
<QuoteEmbed quote={quote} />
</View>
{quote.uri !== initQuote?.uri && (
<QuoteX onRemove={() => setQuote(undefined)} />
<QuoteX
onRemove={() => {
dispatch({type: 'embed_remove_quote'})
setQuote(undefined)
}}
/>
)}
</View>
) : null}
Expand Down
Loading

0 comments on commit 992a5e8

Please sign in to comment.