-
Notifications
You must be signed in to change notification settings - Fork 33
homepage image endpoint + random image on home screen #1978
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06dfaa9
homepage image endpoint + random image on home screen
jctimbol 7268907
move array + helper fcn to util file
jctimbol 3d49261
homepage image endpoint returns url and alt; update file names
jctimbol bf3aa14
add visit counter to home page
jctimbol 9f9d883
revert visit count changes; moved to new pr
jctimbol cbb921c
whitespace fixes; tweak image api url handling
jctimbol 97fdd9e
getting there
evanugarte 54365fd
list of images
evanugarte f1e6a42
all done
evanugarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| const express = require ('express'); | ||
| const router = express.Router(); | ||
| const { OK, NOT_FOUND } = require('../../util/constants').STATUS_CODES; | ||
|
|
||
| const imageUrls = [ | ||
| {url: 'https://live.staticflickr.com/2182/2377582173_89e0ca2f83_b.jpg', alt: 'empty room'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/2022intern.jpg', alt: '2022intern'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/2023_spring.jpg', alt: '2023_spring'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/2025intern.jpg', alt: '2025 intern'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/4monitor.jpg', alt: 'using 4 monitors in sce'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/alumni_visit.jpg', alt: 'alumni visit'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/alumni_visit2.jpg', alt: 'alumni visit'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/cleezy_demo.jpg', alt: 'cleezy_demo'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/companytour.jpg', alt: 'companytour'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/dragon.jpg', alt: 'dragon'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/endofyear.jpg', alt: 'endofyear'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/game.jpg', alt: 'game'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/hackathon.jpg', alt: 'hackathon'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/hackinit.jpg', alt: 'working in the hardware lab'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/kahoot.jpg', alt: 'kahoot'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/lego.jpg', alt: 'lego'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/piza.jpg', alt: 'pizza'}, | ||
| {url: 'https://raw.githubusercontent.com/SCE-Development/Clark/93b422f177118942b725bbe090ea8d50abd3c1c3/public/scemakescoffee.jpg', alt: 'sce makes coffee'}, | ||
| ]; | ||
|
|
||
| const getRandomImage = () => { | ||
| if(imageUrls.length === 0) return null; | ||
| return imageUrls[Math.floor(Math.random() * imageUrls.length)]; | ||
| }; | ||
|
|
||
| router.get('/Homepage', (req, res) => { | ||
| const image = getRandomImage(); | ||
| if(!image) return res.sendStatus(NOT_FOUND); | ||
| res.status(OK).send(image); | ||
| }); | ||
|
|
||
| module.exports = router; | ||
This file contains hidden or 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,20 @@ | ||
| import { ApiResponse } from './ApiResponses'; | ||
| import { BASE_API_URL } from '../Enums'; | ||
|
|
||
| export async function getHomeImage() { | ||
| let status = new ApiResponse(); | ||
| try { | ||
| const url = new URL('/api/Image/Homepage', BASE_API_URL); | ||
| const res = await fetch (url.href); | ||
| if (res.ok) { | ||
| const result = await res.json(); | ||
| status.responseData = result; | ||
| } else { | ||
| status.error = true; | ||
| } | ||
| } catch (err) { | ||
| status.responseData = err; | ||
| status.error = true; | ||
| } | ||
| return status; | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.