Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OV-377: Create preview page and flow #429

Merged
merged 23 commits into from
Sep 27, 2024

Conversation

stefano-lacorazza
Copy link
Collaborator

Summary:

This pull request implements the following features:

  1. Preview Page Creation:

    • Created a whitelisted separate Preview page, accessible via a generated JWT-based URL.
    • Added a video player to this page for playback of the video.
  2. Button for Generating Preview Link:

    • Added a button to each rendered video on the homepage to copy the preview link.
    • When the button is clicked, a request is sent to the backend to generate a JWT containing the video ID.
  3. JWT-based Preview URL Generation:

    • Added an endpoint to generate a preview URL with a JWT and the videoId.
    • The server response returns a URL string with the format preview/:jwt, which includes the JWT and the video ID.
    • Upon receiving the server response, the preview URL is copied to the clipboard.
  4. Preview URL Access and JWT Decoding:

    • When a user accesses the preview URL, the JWT and videoId are extracted from the page URL.
    • A request is sent to decode the JWT and retrieve the videoId.
    • The decoded videoId is then used to fetch the corresponding video URL for playback.
  5. New Public-Video Controller:

    • Implemented a new public-video controller to handle requests related to video previews, including decoding JWTs and retrieving video information.
OutreachVids.-.Google.Chrome.2024-09-25.09-10-12.mp4

@stefano-lacorazza stefano-lacorazza added the FE Fronted feature label Sep 25, 2024
@stefano-lacorazza stefano-lacorazza added this to the Final DEMO milestone Sep 25, 2024
@stefano-lacorazza stefano-lacorazza self-assigned this Sep 25, 2024
@stefano-lacorazza stefano-lacorazza linked an issue Sep 25, 2024 that may be closed by this pull request
9 tasks
@@ -0,0 +1,7 @@

const createVideoUrl = (jwtToken: string): string => {
const baseUrl = 'http://localhost:3000';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here how could I create the baseUrl dynamically for deployment?

@stefano-lacorazza stefano-lacorazza added the BE Backend feature label Sep 25, 2024
Comment on lines 20 to 26
public async createVideoIdToken(videoId: string): Promise<string> {
const jwt = await new SignJWT({ videoId })
.setProtectedHeader({ alg: 'HS256' })
.sign(this.secretKey);
return jwt.replaceAll('.', '~');
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move it to video service

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use createToken method and set expiration time optional?


public async getVideoIdFromToken(token: string): Promise<string | null> {
const payload = await this.verifyToken(token);
return (payload?.['videoId'] as string) || null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (payload?.['videoId'] as string) || null;
return (payload?.['videoId'] as string) ?? null;

const Preview: React.FC<Properties> = ({ jwt }) => {
const dispatch = useAppDispatch();
const [url, setUrl] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoading, setIsLoading

@@ -0,0 +1,10 @@
const createVideoUrl = (jwtToken: string): string => {
const baseUrl =
import.meta.env['VITE_APP_NODE_ENV'] === 'production'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use our class on frontend to handle .env

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use this
image

Comment on lines 6 to 9
config.ENV.APP.ENVIRONMENT === AppEnvironment.PRODUCTION
? 'http://bsa-2024-outreachvids-dev.eu-north-1.elasticbeanstalk.com'
: 'http://localhost:3000';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new env variable and use it. What if the deployment URL changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but could you test it if it was done correctly before merging? I have no way of testing in production enviroment and I dont want to break something a day before the demo. Thank you

Comment on lines 32 to 37
const videoTokenHeader = headers['video_token']?.toString() ?? '';

return {
status: HTTPCode.OK,
payload: await this.publicVideoService.findUrlByToken(
videoTokenHeader ?? '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this nullish coalescing here? You already check it on line 32

this.throwVideoNotFoundError();
}

const url = video.toObject().url;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const url = video.toObject().url;
const { url } = video.toObject();

@@ -109,6 +109,17 @@ class VideoController extends BaseController {
}>,
),
});
this.addRoute({
path: `${VideosApiPath.ID}/share`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this path to the enum


public async getVideoIdJWT(id: string): Promise<string> {
const response = await this.load(
this.getFullEndpoint(`${VideosApiPath.ROOT}${id}/share`, {}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

? 'http://bsa-2024-outreachvids-dev.eu-north-1.elasticbeanstalk.com'
? config.ENV.DEPLOYMENT.URL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add something like PUBLIC_URL. And use it as it is without checks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im having problems with this one. I changed .env, EnvironmentSchema, and base-config.package adding the new ENV PUBLIC_URL variable but when I try to access it in createVideoUrl I keep getting undefined.

Comment on lines 14 to 17
#
# DEPLOYMENT
#
DEPLOYMENT_URL=http://bsa-2024-outreachvids-dev.eu-north-1.elasticbeanstalk.com
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#
# DEPLOYMENT
#
DEPLOYMENT_URL=http://bsa-2024-outreachvids-dev.eu-north-1.elasticbeanstalk.com
#
# DEPLOYMENT
#
PUBLIC_URL=http://localhost:3000

@nikita-remeslov nikita-remeslov merged commit 264640c into next Sep 27, 2024
2 checks passed
@nikita-remeslov nikita-remeslov deleted the task/OV-377-create-preview-page branch September 27, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE Backend feature FE Fronted feature
Projects
Status: To Be Tested
Development

Successfully merging this pull request may close these issues.

FEAT: Create preview page
4 participants