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

image search app #239

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.env
node_modules
dist
27 changes: 27 additions & 0 deletions correct sum_of_n numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>

int main() {
int n, i;
double sum = 0.0;

printf("Enter the number of elements: ");
scanf("%d", &n);

if (n <= 0) {
printf("Invalid input. Please enter a positive integer.\n");
return 1; // Exit with an error code
}

printf("Enter %d numbers:\n", n);

for (i = 1; i <= n; ++i) {
double num;
printf("Enter number %d: ", i);
scanf("%lf", &num);
sum += num;
}

printf("Sum = %.2lf\n", sum);

return 0;
}
76 changes: 10 additions & 66 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,69 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up Page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">


<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div class="container">

<form action="" class="form" id="form">
<div class="form-control">
<label>First Name</label>
<input type="text" id="username" placeholder="Enter First Name" autocomplete="off" required>
</div>

<div class="form-control">
<label>Last Name</label>
<input type="text" id="lastname" placeholder="Enter Last Name" autocomplete="off" required >

</div>

<div class="form-control">
<label>Email</label>
<input type="text" id="email" placeholder="[email protected]" autocomplete="off" required>

</div>

<div class="form-control">
<label>Password</label>
<input type="password" id="password" placeholder="Enter Your Password" autocomplete="off">
<i class="fas fa-check-circle"></i>
<i class="fas fa-exclamation-circle"></i>
<small>Error Message</small>
</div>

<div class="form-control">
<label>Confirm Password</label>
<input type="password" id="cpassword" placeholder="Confirm Password" autocomplete="off">
<i class="fas fa-check-circle"></i>
<i class="fas fa-exclamation-circle"></i>
<small>Error Message</small>
</div>

<button class="button signup__submit">
<span class="button__text">Sign Up</span>
</button><br>
<div class="social-media">
<a href=""><i class="fa-brands fa-square-instagram"></i></a>
<a href=""><i class="fa-brands fa-linkedin"></i></a>
<a href=""><i class="fa-brands fa-twitter"></i></a>
<a href=""><i class="fa-brands fa-github"></i></a>

</div>
</form>
</div>


<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<script src="script.js"></script>
</body>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
98 changes: 98 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import express, { Express, Request, Response } from "express";
import dotenv from "dotenv";
import cors from "cors";
import { createApi } from "unsplash-js";
import { Random, Stats } from "unsplash-js/dist/methods/photos/types";
import bodyParser from "body-parser";
import fetch from "cross-fetch";

dotenv.config();

const app: Express = express();

app.use(
cors({
origin: true,
methods: ["GET", "PUT", "POST"],
allowedHeaders: [
"Origin, X-Requested-With, Content, Accept, Content-Type, Authorization",
],
exposedHeaders: ["Content-Range", "X-Content-Range"],
})
);

const port = process.env.PORT || 3000;

app.get("/", (req: Request, res: Response) => {
res.send("hell0 " + port);
});

var urlencodedParser = bodyParser.urlencoded({ extended: true });

const api = createApi({ accessKey: `${process.env.UNSPLASH_API_KEY}`, fetch });

type randomImage = Random & Stats;

function mapRandomSearchData(items: randomImage) {
const data = {
id: items.id,
likes: items.likes,
userName: items.user.name,
userTag: items.user.username,
userProfilePhoto: items.user.profile_image.small,
imageLink: items.urls.regular,
downloadImage: items.links.download,
info: items.alt_description,
info_alt: items.description,
twitterTag: items.user.twitter_username,
instagramTag: items.user.instagram_username,
downloads: items.downloads,
};

return {
...data,
};
}

const getRandomPhotos = async (query?: string) => {
let reportArray;
try {
await api.photos.getRandom({ count: 33, query: query }).then((response) => {
if (response.type === "success") {
const responseArray = response.response as randomImage[];
reportArray = JSON.stringify(
responseArray.map((items) => mapRandomSearchData(items))
);
} else {
throw new Error("failed getting dat from api");
}
});
} catch (err) {
console.log("Error setting up Unsplash API:" + err);
}
return reportArray;
};

app.get("/generateRandomImages", (req: Request, res: Response) => {
getRandomPhotos().then((array) => {
res.json({ data: array });
console.log({ data: array });
});
});

app.post(
"/searchImages",
urlencodedParser,
bodyParser.json(),
(req: Request, res: Response) => {
const query = req.body.query;
getRandomPhotos(query).then((array) => {
res.json({ data: array });
console.log({ data: array });
});
}
);

app.listen(port, () => {
console.log("port running");
});
Loading