diff --git a/docs/controller.md b/docs/controller.md index 7629d62..90a8e3d 100644 --- a/docs/controller.md +++ b/docs/controller.md @@ -91,3 +91,36 @@ Validator sends messages to 3. If Validator didn't participated in election, he must return unused load. Otherwise, anybody can `return_unused_loan` and get `STAKE_RECOVER_FINE`, in particular: > If controller is in "rest" state, `borrowed_amount > 0` and `utime_since > borrowed_time`, controller has enough funds on balance, anybody can trigger `return_unused_loan` and get reward + +## Image Upload Functionality + +### Process of Uploading Images to the Server + +To upload an image to the server, follow these steps: + +1. Send a POST request to the server with the image file included in the request body. +2. The server will process the image and store it in the designated directory. +3. The server will return a response containing the URL of the uploaded image. + +### Example Image Upload Request + +```http +POST /upload +Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW + +------WebKitFormBoundary7MA4YWxkTrZu0gW +Content-Disposition: form-data; name="image"; filename="example.jpg" +Content-Type: image/jpeg + + +------WebKitFormBoundary7MA4YWxkTrZu0gW-- +``` + +### Example Image Upload Response + +```json +{ + "success": true, + "url": "https://example.com/uploads/example.jpg" +} +``` diff --git a/docs/get-method-interface.md b/docs/get-method-interface.md index fbb2b82..4a2471c 100644 --- a/docs/get-method-interface.md +++ b/docs/get-method-interface.md @@ -73,3 +73,48 @@ Projected pool jetton/TON ratio is equal to `projected_total_balance/projected_s - `validator` - `slice` - address of validator wallet - `pool` - `slice` - address of pool wallet - `sudoer` - `slice` - address of sudoer wallet + +# Image Upload Methods + +## Parameters and Return Values for Image Upload Methods + +### Parameters + +- `image`: The image file to be uploaded. +- `filename`: The name of the image file. +- `content_type`: The MIME type of the image file. + +### Return Values + +- `success`: A boolean indicating whether the upload was successful. +- `url`: The URL of the uploaded image. + +## Example Image Upload Method Calls + +### Example 1: Uploading a JPEG Image + +```http +POST /upload +Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW + +------WebKitFormBoundary7MA4YWxkTrZu0gW +Content-Disposition: form-data; name="image"; filename="example.jpg" +Content-Type: image/jpeg + + +------WebKitFormBoundary7MA4YWxkTrZu0gW-- +``` + +### Example 2: Uploading a PNG Image + +```http +POST /upload +Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW + +------WebKitFormBoundary7MA4YWxkTrZu0gW +Content-Disposition: form-data; name="image"; filename="example.png" +Content-Type: image/png + + +------WebKitFormBoundary7MA4YWxkTrZu0gW-- +``` diff --git a/package.json b/package.json index c8181b6..9f087d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liquid_staking", - "version": "0.0.1", + "version": "0.0.2", "license": "MIT", "scripts": { "test": "jest" @@ -18,6 +18,7 @@ "ton-crypto": "^3.2.0", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", - "typescript": "^4.9.5" + "typescript": "^4.9.5", + "multer": "^1.4.4" } } diff --git a/scripts/deployPool.ts b/scripts/deployPool.ts index fb2a7d8..d72c87d 100644 --- a/scripts/deployPool.ts +++ b/scripts/deployPool.ts @@ -6,7 +6,22 @@ import { compile, NetworkProvider, sleep } from '@ton-community/blueprint'; import {JettonWallet as PoolJettonWallet } from '../wrappers/JettonWallet'; import { Controller } from '../wrappers/Controller'; import { Librarian, LibrarianConfig } from '../wrappers/Librarian'; +import multer from 'multer'; +import express from 'express'; +import path from 'path'; +const app = express(); +const upload = multer({ dest: 'uploads/' }); + +app.post('/upload', upload.single('image'), (req, res) => { + if (!req.file) { + return res.status(400).json({ success: false, message: 'No file uploaded' }); + } + const imageUrl = `${req.protocol}://${req.get('host')}/uploads/${req.file.filename}`; + res.status(200).json({ success: true, url: imageUrl }); +}); + +app.use('/uploads', express.static(path.join(__dirname, 'uploads'))); const waitForTransaction = async (provider:NetworkProvider, address:Address, action:string = "transaction",