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

New upload image route #360

Open
Marchand-Nicolas opened this issue Dec 26, 2024 · 27 comments · May be fixed by #370
Open

New upload image route #360

Marchand-Nicolas opened this issue Dec 26, 2024 · 27 comments · May be fixed by #370
Assignees
Labels
Good first issue Good for newcomers OD Boost Issue reserved for the OD Boost open for contribution An issue that is available for an Only Dust contribution

Comments

@Marchand-Nicolas
Copy link
Collaborator

Description 📹

Create a new src/endpoints/admin/upload_image admin route that allows uploading an image to a ./images folder. The route should accept two parameters: an image and an image name. The image should be saved as ./images/image_name.webp.

Proposed Actions 🛠️

Here’s a checklist of actions to follow for resolving this issue:

  1. Fork and Create Branch:
    Fork the repository and create a new branch using the issue number:
   git checkout -b fix-[issue-number]
  1. Implement Changes:
    • Create a new file in src/endpoints/admin/ named upload_image.rs.
    • Add the following implementation for the upload_image admin route:
use axum::{
    extract::{Multipart, Path},
    http::StatusCode,
    response::IntoResponse,
    routing::post,
    Router,
};
use std::{fs::create_dir_all, path::Path as FilePath};

pub async fn upload_image_handler(
    Path(image_name): Path<String>,
    mut multipart: Multipart,
) -> impl IntoResponse {
    let images_folder = "./images";
    if !FilePath::new(images_folder).exists() {
        create_dir_all(images_folder).unwrap();
    }

    while let Some(field) = multipart.next_field().await.unwrap() {
        if let Some(filename) = field.file_name() {
            if filename.ends_with(".webp") {
                let filepath = format!("{}/{}.webp", images_folder, image_name);
                let data = field.bytes().await.unwrap();
                tokio::fs::write(filepath, data).await.unwrap();
                return StatusCode::OK.into_response();
            } else {
                return (StatusCode::BAD_REQUEST, "Only .webp files are allowed").into_response();
            }
        }
    }

    (StatusCode::BAD_REQUEST, "No valid file provided").into_response()
}

pub fn admin_routes() -> Router {
    Router::new().route("/admin/upload_image/:image_name", post(upload_image_handler))
}
  • Update the main router configuration to include the new admin route.
  1. Run Tests and Commit Changes:
    Ensure the route works as expected and passes the following tests:

    • File is saved as image_name.webp in the ./images folder.
    • Only .webp files are accepted.
    • The directory ./images is created if it doesn’t exist.

    Use HTTPie to test the endpoint by sending a request with a .webp image.

    Commit your changes with a clear message:

   git commit -m "Fix: Added upload_image admin route for image uploads"

Required 📋

To keep our workflow smooth, please make sure you follow these guidelines:

  • Assignment: Don't create a pull request if you weren’t assigned to this issue.
  • Timeframe: Complete the task within 3 business days.
  • Closing the Issue: In your PR description, close the issue by writing Close #[issue_id].
  • Review Process:
    • Once you've submitted your PR, change the label to "ready for review".
    • If changes are requested, address them and then update the label back to "ready for review" once done.
  • Testing: Test your PR locally before pushing, and verify that tests and build are working after pushing.

Thank you for your contribution 🙏

⚠️ WARNING: Failure to follow the requirements above may result in being added to the OnlyDust blacklist, affecting your ability to receive future rewards.

@Marchand-Nicolas Marchand-Nicolas added Good first issue Good for newcomers open for contribution An issue that is available for an Only Dust contribution OD Boost Issue reserved for the OD Boost labels Dec 26, 2024
@No-bodyq
Copy link

Could I take on this issue?

@Agbeleshe
Copy link

Is it okay if I tackle this?
I will love to make this my first contribution to the starknet Quest

@ryzen-xp
Copy link
Contributor

Can I take care of this issue?

1 similar comment
@Supa-mega
Copy link
Contributor

Can I take care of this issue?

@VyuduInc
Copy link

Would love to tackle this!

@847850277
Copy link
Contributor

Could I take on this issue?

@mahaitao617
Copy link

Can I take this from here?

@michojekunle
Copy link

I'd love to work on this!

@PrathamJha1
Copy link

Would love to contribute here , given my experience as a JavaScript and Typescript developer working in the Web3 space for over a year.

@aidenwong812
Copy link
Contributor

Let me try this one!

@aurlic
Copy link
Contributor

aurlic commented Jan 6, 2025

Could I be assigned to this?

@Thibrac
Copy link
Contributor

Thibrac commented Jan 7, 2025

Can I jump on this task?

@emarc99
Copy link

emarc99 commented Jan 7, 2025

May I pick this up?

@rohithc123
Copy link

May I be assigned to this?

@thedevtask
Copy link

May I handle this issue?

@OthmanImam
Copy link

Can I attempt this issue?

@olisaagbafor
Copy link

Is it okay if I tackle this?

@pheobeayo
Copy link

Could I try solving this?

@QuenumGerald
Copy link

I’d like to help with this.

@chiscookeke11
Copy link

Can I attempt this issue?

@crood-xp
Copy link

Can I take this issue?

@Kingsuite
Copy link
Contributor

Can I be assigned to this?

@salazarsebas
Copy link

My background

I'm a software engineer and passionate about solving problems, I've been contributing to open source software for a few months and it's an experience that has taught me a lot and I really like to contribute to other projects. I am a member of the Dojo Coding community⛩️. I will dedicate all my effort to complete this issue in the best way.

@SudiptaPaul-31
Copy link

Could I take on this issue?

@ussyalfaks
Copy link

I’d like to work on this.

@suhas-sensei
Copy link
Contributor

gm serI’d like to work on this issue. I have experience with Rust, Axum, and similiar, and I can implement the upload_image admin route to handle .webp image uploads efficiently. Please assign me this task!

@salazarsebas salazarsebas linked a pull request Jan 22, 2025 that will close this issue
3 tasks
@salazarsebas
Copy link

Thank you for assigning me this issue, I have already sent my pr, it is a pleasure to contribute to this great project. 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Good for newcomers OD Boost Issue reserved for the OD Boost open for contribution An issue that is available for an Only Dust contribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.