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

Додати функціональність завантаження зображень #68

Open
wants to merge 1 commit 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
33 changes: 33 additions & 0 deletions docs/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<image data>
------WebKitFormBoundary7MA4YWxkTrZu0gW--
```

### Example Image Upload Response

```json
{
"success": true,
"url": "https://example.com/uploads/example.jpg"
}
```
45 changes: 45 additions & 0 deletions docs/get-method-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<image data>
------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

<image data>
------WebKitFormBoundary7MA4YWxkTrZu0gW--
```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liquid_staking",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"scripts": {
"test": "jest"
Expand All @@ -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"
}
}
15 changes: 15 additions & 0 deletions scripts/deployPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down