Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d74605
Update preferences to match API
Oct 12, 2026
3758d04
fix file structure for tests
helenul Oct 12, 2026
0ddccc7
refactured and re-organized the code
helenul Oct 12, 2026
7e6200b
More re-facturing
alexajah Oct 12, 2026
026b8fe
fix file imports after name change
helenul Oct 12, 2026
ba6fb3e
delete unnessesary files
helenul Oct 12, 2026
7e79b31
ran linting and prettier in frontend
alexajah Oct 12, 2026
0ef139b
ran prettier and linting in backend and installed linting
alexajah Oct 12, 2026
9e290bc
re-organized more!
alexajah Oct 12, 2026
200603d
updated so linting and prettier can be run from rot-file and added ce…
alexajah Oct 13, 2026
54fa0c9
fixed minor issues and typos
alexajah Oct 13, 2026
a4e3e1a
updated readME and created files
alexajah Oct 13, 2026
65953e2
prettier run
alexajah Oct 13, 2026
bf9cb85
Add photos from wikimedia
Oct 12, 2026
1356ebf
Add plant card image placeholder
Oct 12, 2026
7673356
Style frontpage so everything is visible
Oct 12, 2026
c9d9ccc
delete raw data files and the package-lock.json
helenul Oct 13, 2026
d943d94
run lint and prettier
helenul Oct 13, 2026
e04b822
Remove raw data and run linting/formatting
Oct 13, 2026
459f0e1
Fix merge conflict
Oct 13, 2026
af94675
Update preferences to match API
Oct 12, 2026
38cf2de
Show matching preferences on plant card
Oct 12, 2026
68dd5ce
Fix to use preferences that are actually available
Oct 12, 2026
435df09
Add arrow to information and back buttons
Oct 12, 2026
d08fd4e
Fix dark mode readability on plantcard preferences
Oct 12, 2026
c883323
Merge wish main
Oct 13, 2026
eaa013a
Fix correct preferences on profile page
Oct 13, 2026
7fb0fc7
Add empty card for when out of plants
Oct 13, 2026
7dddd7c
Fix plantcard size
Oct 14, 2026
489bb10
Merge main and preserve preference matching design
Oct 14, 2026
169c9a7
Move plantpreferences to own directory, fix styling plantcard
Oct 15, 2026
f1bad84
Resolve package-lock conflict
Oct 15, 2026
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
7 changes: 0 additions & 7 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface PlantDoc {
commonName: string;
// Base64-encoded Perenual image as a data URI, stored by seedDataFetch.js
imageData?: string | null;
imageURL?: string | null;
scientificName?: string[];
description?: string;
watering?: string;
Expand Down Expand Up @@ -49,14 +50,14 @@ const typeDefs = `
sunlight: [String]
careLevel: String}
`;

const toPlant = (doc: WithId<PlantDoc>): Plant => ({
id: doc._id.toString(),
name: doc.commonName,
imageURL: doc.imageData ?? null,
imageURL: doc.imageData ?? doc.imageURL ?? null,
scientificName: doc.scientificName,
description: doc.description,
watering: doc.watering,
Expand All @@ -81,6 +82,7 @@ const resolvers = {
$project: {
commonName: 1,
imageData: 1,
imageURL: 1,
scientificName: 1,
description: 1,
watering: 1,
Expand Down
64 changes: 64 additions & 0 deletions backend/src/updatePlantImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { db } from "./db.js";
import { getWikimediaImage } from "./wikimedia.js";

interface PlantDoc {
commonName: string;
scientificName?: string[];
imageURL?: string | null;
}

const plants = db.collection<PlantDoc>("plants");

async function updatePlantImages() {
const docs = await plants.find({}).toArray();

console.log(`Fant ${docs.length} planter`);

for (const doc of docs) {
const scientificName = doc.scientificName?.[0];

if (!scientificName) {
console.log(`Mangler scientificName: ${doc.commonName}`);
continue;
}

try {
console.log(`Søker etter: ${scientificName}`);

const imageURL = await getWikimediaImage(scientificName);

if (!imageURL) {
console.log(`Fant ikke bilde for ${scientificName}`);

await plants.updateOne(
{ _id: doc._id },
{
$set: {
imageURL: null,
},
},
);

continue;
}

await plants.updateOne(
{ _id: doc._id },
{
$set: {
imageURL,
},
},
);

console.log(`✓ Oppdaterte ${doc.commonName}`);
} catch (error) {
console.error(`Feil ved henting av bilde for ${scientificName}:`, error);
}
}

console.log("Ferdig!");
process.exit(0);
}

updatePlantImages();
47 changes: 47 additions & 0 deletions backend/src/wikimedia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export async function getWikimediaImage(scientificName: string) {
const params = new URLSearchParams({
action: "query",
generator: "search",
gsrsearch: scientificName,
gsrnamespace: "6",
gsrlimit: "10",
prop: "imageinfo",
iiprop: "url|mime|extmetadata",
format: "json",
origin: "*",
});

const response = await fetch(
`https://commons.wikimedia.org/w/api.php?${params}`,
);

if (!response.ok) {
throw new Error(`Wikimedia svarte med status ${response.status}`);
}

const data = await response.json();

const pages = data.query?.pages;

if (!pages) {
return null;
}

const results = Object.values(pages) as {
imageinfo?: { url?: string; mime?: string }[];
}[];

const allowedMimeTypes = ["image/jpeg", "image/png", "image/webp"];

const image = results.find((page) => {
const info = page.imageinfo?.[0];

if (!info?.url || !info?.mime) {
return false;
}

return allowedMimeTypes.includes(info.mime);
});

return image?.imageinfo?.[0]?.url ?? null;
}
Loading
Loading