Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlevy0 committed Dec 1, 2023
1 parent 495f7c6 commit 029b4bb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
7 changes: 7 additions & 0 deletions amplify/backend/function/S3Trigger52a3ac74/lib/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ export async function download(Bucket: string, Key: string, filePath: string) {
Bucket: _Bucket,
Key: _key,
})
console.log(`key :${Key}`)
console.log(`_key :${_key}`)
console.log(`Bucket :${Bucket}`)
console.log(`_Bucket :${_Bucket}`)

const { Body } = await s3.getObject({ Bucket: _Bucket, Key: _key })

console.log(`Body :${Body}`)

let downloadedBytes = 0
let updateInProgress = false

Expand Down
4 changes: 2 additions & 2 deletions amplify/backend/function/S3Trigger52a3ac74/lib/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function processVideo(_in: string, _out: string) {
const ffmpegCommand = getCmd(_in, batchOutput, batchShots)
await execPromise(ffmpegCommand)
} catch (error) {
console.log('--ERROR execPromise :')
console.log(`--ERROR execPromise : ${error}`)
throw new Error(error)
}
}
Expand All @@ -97,7 +97,7 @@ export async function processVideo(_in: string, _out: string) {
const concatCommand = `ffmpeg -f concat -safe 0 -i "${concatFile}" -c copy "${_out}"`
await execPromise(concatCommand)
} catch (error) {
console.log('--ERROR concat execPromise :')
console.log(`--ERROR concat execPromise : ${error}`)
throw new Error(error)
}

Expand Down
48 changes: 33 additions & 15 deletions src/app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,21 @@ export const Main = () => {
</Button>
</Grid>
</Flex>
// : <Clip />
: (
<Flex flex={1} width={"100%"}>
<iframe
style={{
width: "100%", height: "100%"
}}
src="https://clip-crafter-studio-web-service.onrender.com" frameBorder="0" ></iframe>
</Flex >
)
: <Clip />
// : (
// <Flex flex={1} width={"100%"}>
// <iframe
// title="alexlevy0/ClipCrafterStudio/main"
// allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
// sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
// frameBorder="0"
// style={{ width: "100%", height: "100%" }}
// // src="https://codesandbox.io/p/github/alexlevy0/ClipCrafterStudio/main?file=%2F.codesandbox%2Ftasks.json&embed=1"
// src="https://clip-crafter-studio-web-service.onrender.com"
// >
// </iframe>
// </Flex >
// )
}

return (
Expand Down Expand Up @@ -278,7 +283,7 @@ export const Main = () => {
columnEnd="2"
variation="elevated"
>
<Clip />
{/* <Clip /> */}
</Card>
<Card
columnStart="2"
Expand Down Expand Up @@ -375,6 +380,7 @@ const Clip = () => {
const PROCESSING = 'Processing'

const [url, setUrl] = useState('')
const [urlEdited, setUrlEdited] = useState('')
const [status, setStatus] = useState(STANDBY)

const onReady = () => {
Expand All @@ -385,9 +391,12 @@ const Clip = () => {
if (!key) return
setStatus(`${PROCESSING} : ${key}…`)
// @ts-ignore
const url = await retry({ fn: async () => await getData(key) })
const url = await retry({ fn: async () => await getData(key, '') })
console.log({ url });
setUrl(url)
const urlEdited = await retry({ fn: async () => await getData(key) })
console.log({ urlEdited });
setUrlEdited(urlEdited)
}

const onResetVideoUrl = () => setUrl('')
Expand All @@ -412,14 +421,14 @@ const Clip = () => {
onUploadStart={onResetVideoUrl}
components={{ FilePicker({ onClick }) { return <Picker onClick={onClick} /> } }}
/>
<Flex direction="column" gap="small">
{/* <Flex direction="column" gap="small">
<Input
size="small"
width="100%"
enterKeyHint="send"
placeholder="Paste YouTube link or drop a file"
/>
</Flex>
</Flex> */}
{status !== READY && status !== STANDBY && (
<Flex
backgroundColor={'rgb(13, 25, 38)'}
Expand All @@ -440,9 +449,10 @@ const Clip = () => {
</Flex>
)}
<Flex
backgroundColor={'black'}
// backgroundColor={'black'}
alignContent="center"
justifyContent={'center'}
gap="small"
>
<ReactPlayer
style={{ backgroundColor: 'black' }}
Expand All @@ -452,6 +462,14 @@ const Clip = () => {
url={url}
width={"100%"}
/>
<ReactPlayer
style={{ backgroundColor: 'grey' }}
onReady={onReady}
playing={true}
controls={true}
url={urlEdited}
width={"100%"}
/>
</Flex>
</Flex>
);
Expand Down
47 changes: 29 additions & 18 deletions src/app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
import { Storage } from 'aws-amplify';
import { Storage } from 'aws-amplify'

export const noop = async () => {
undefined
}

export const noop = async () => { undefined }

export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
export const sleep = (ms: number) =>
new Promise(resolve => setTimeout(resolve, ms))

export const retry = async ({ fn = noop, retries = 120, delay = 4000, err = '' }) => {
const attempt = async (remainingRetries: number, lastError = null): Promise<any> => {
export const retry = async ({
fn = noop,
retries = 120,
delay = 4000,
err = '',
}) => {
const attempt = async (
remainingRetries: number,
lastError = null,
): Promise<any> => {
if (remainingRetries <= 0) {
throw new Error(`RemainingRetries ${retries}, ${lastError}`);
throw new Error(`RemainingRetries ${retries}, ${lastError}`)
}
try {
return await fn();
return await fn()
} catch (error) {
await sleep(delay);
return attempt(remainingRetries - 1);
await sleep(delay)
return attempt(remainingRetries - 1)
}
};
}

return attempt(retries);
return attempt(retries)
}


export const getData = async (key: string) => {
export const getData = async (key: string, prefix = '_edited') => {
try {
const config = {
validateObjectExistence: true,
download: false, expires: 3600
download: false,
expires: 3600,
}
const [name, format] = key.split('.')
const newKey = `${name}_edited.${format}`
const newKey = `${name}${prefix}.${format}`
console.log({ newKey })
return await Storage.get(newKey, config)
} catch (error) {
throw new Error("No data yet");
throw new Error('No data yet')
}
}
}

0 comments on commit 029b4bb

Please sign in to comment.