-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
457 upload the last image from hypso 1 and hypso 2 (#461)
* feat: adding a tab bar for the satellite individual page * feat: uploading the last images of satellite * fix: lint * fix lint
- Loading branch information
Thibault
authored and
GitHub
committed
Jun 26, 2025
1 parent
4ae5217
commit f9e3e9f
Showing
17 changed files
with
1,082 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * satellite controller | ||
| */ | ||
|
|
||
| const { createCoreController } = require('@strapi/strapi').factories; | ||
| const { createCoreController } = require("@strapi/strapi").factories; | ||
|
|
||
| module.exports = createCoreController('api::satellite.satellite'); | ||
| module.exports = createCoreController("api::satellite.satellite"); |
This file contains 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * satellite router | ||
| */ | ||
|
|
||
| const { createCoreRouter } = require('@strapi/strapi').factories; | ||
| const { createCoreRouter } = require("@strapi/strapi").factories; | ||
|
|
||
| module.exports = createCoreRouter('api::satellite.satellite'); | ||
| module.exports = createCoreRouter("api::satellite.satellite"); |
This file contains 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,58 @@ | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * A set of functions called "actions" for `slack` | ||
| */ | ||
|
|
||
| // esl-lint-disable-next-line no-unused-vars | ||
| const fetchImagesFromSlack = require("../services/slack"); | ||
| const fetch = require("node-fetch"); | ||
|
|
||
| module.exports = { | ||
| fetchImages: async (ctx) => { | ||
| try { | ||
| const images = await strapi | ||
| .service("api::slack.slack") | ||
| .fetchImagesFromSlack(); | ||
| return ctx.send(images); | ||
| } catch (error) { | ||
| return ctx.throw( | ||
| 500, | ||
| "Error fetching images from Slack: " + error.message | ||
| ); | ||
| } | ||
| }, | ||
| getSharedURL: async (ctx) => { | ||
| const { fileId } = ctx.request.body; | ||
| const slackToken = process.env.SLACK_BOT_TOKEN; | ||
|
|
||
| if (!fileId) { | ||
| return ctx.badRequest("File ID is required"); | ||
| } | ||
|
|
||
| try { | ||
| const response = await fetch( | ||
| "https://slack.com/api/files.sharedPublicURL", | ||
| { | ||
| method: "POST", | ||
| headers: { | ||
| Authorization: `Bearer ${process.env.SLACK_USER_TOKEN}`, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body: JSON.stringify({ file: fileId }), | ||
| } | ||
| ); | ||
|
|
||
| const data = await response.json(); | ||
| if (!data.ok && !data.error.includes("already_public")) { | ||
| throw new Error(data.error || "Failed to make the image public"); | ||
| } | ||
| ctx.send({ | ||
| message: "Image has been made public successfully", | ||
| }); | ||
| } catch (error) { | ||
| console.error("Error generating public URL:", error); | ||
| ctx.internalServerError("Failed to make the image URL " + fileId); | ||
| } | ||
| }, | ||
| }; |
This file contains 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,25 @@ | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * slack routes | ||
| */ | ||
| module.exports = { | ||
| routes: [ | ||
| { | ||
| method: "GET", | ||
| path: "/slack-images", | ||
| handler: "slack.fetchImages", | ||
| config: { | ||
| auth: false, | ||
| }, | ||
| }, | ||
| { | ||
| method: "POST", | ||
| path: "/slack-shared-url", | ||
| handler: "slack.getSharedURL", | ||
| config: { | ||
| auth: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }; |
This file contains 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,45 @@ | ||
| "use strict"; | ||
|
|
||
| const { WebClient } = require("@slack/web-api"); | ||
| const slack = new WebClient(process.env.SLACK_BOT_TOKEN); | ||
|
|
||
| /** | ||
| * slack service | ||
| */ | ||
|
|
||
| let cachedImages = null; | ||
| let cacheTimestamp = null; | ||
|
|
||
| module.exports = { | ||
| fetchImagesFromSlack: async () => { | ||
| const CACHE_DURATION = 60 * 1000; // 1 minute | ||
| const now = Date.now(); | ||
|
|
||
| if ( | ||
| cachedImages && | ||
| cacheTimestamp && | ||
| now - cacheTimestamp < CACHE_DURATION | ||
| ) { | ||
| console.log("Returning cached images"); | ||
| return cachedImages; | ||
| } | ||
|
|
||
| try { | ||
| const result = await slack.conversations.history({ | ||
| channel: process.env.SLACK_CHANNEL_ID, | ||
| limit: 20, | ||
| }); | ||
| cachedImages = result.messages.filter( | ||
| (msg) => | ||
| msg.bot_profile?.name === "hypso1bot" && | ||
| msg.files && | ||
| msg.files.some((file) => file.mimetype.startsWith("image/")) | ||
| ); | ||
| cacheTimestamp = now; | ||
| return cachedImages; | ||
| } catch (error) { | ||
| console.error("Error fetching images from Slack:", error); | ||
| throw error; | ||
| } | ||
| }, | ||
| }; |
Oops, something went wrong.