Skip to content

Commit

Permalink
fixbug
Browse files Browse the repository at this point in the history
  • Loading branch information
tuminfei committed Dec 26, 2023
1 parent e24518b commit cc689c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
40 changes: 31 additions & 9 deletions app/models/NFTInfo.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ export function converData(data) {
if (data.image && data.image == "null") {
data.image = null;
}
if (data.file_size) {
delete data.file_size;
}
if (data.file_type) {
delete data.file_type;
}
if (data.file_name) {
delete data.file_name;
}
if (data.file_data) {
delete data.file_data;
}

return data;
}

Expand Down Expand Up @@ -93,19 +106,28 @@ export async function canisterUploadImg(
const chunk_size = CHUNK_SIZE;
const file_path = FILE_BASE_PATH + file_name;
const file_headers = [
["Content-Type", "image/jpeg"],
["Content-Type", file_type],
["Cache-Control", "public, max-age=31536000"],
];
const binary_data = Buffer.from(file_data, "base64");
const chunk = new Uint8Array(binary_data);

const service = new NFTCanisterService(nft_collection.canister_id);
const rest = await service.assets_upload(
chunk,
file_path,
chunk.length,
file_headers,
chunk_size
);
return rest;
let image_url = "";
try {
await service.assets_upload(
chunk,
file_path,
chunk.length,
file_headers,
chunk_size
);
image_url =
process.env.NODE_ENV == "production"
? "https://" + nft_collection.canister_id + ".raw.icp0.io" + file_path
: "http://127.0.0.1:4943" + file_path;
} catch (error) {
console.log("assets_upload error");
}
return image_url;
}
4 changes: 2 additions & 2 deletions app/routes/app.nft_infos.$id.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ export async function action({ request, params }) {

// upload image to canister
if (data.file_size && parseInt(data.file_size) > 0) {
await canisterUploadImg(
let image_url = await canisterUploadImg(
parseInt(data.nft_collection_id),
parseInt(data.file_size),
data.file_type,
data.file_name,
data.file_data
);
data.image = image_url;
}

const errors = validateInfo(data);
Expand Down Expand Up @@ -167,7 +168,6 @@ export default function NFTInfoForm() {
data["file_type"] = file.type;
data["file_name"] = file.name;
data["file_data"] = base64data;
data["file"] = file;
}

setCleanFormState({ ...formState });
Expand Down
10 changes: 5 additions & 5 deletions shopify.app.ic-nft-creater.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name = "ic-nft-creater"
client_id = "15957d22030f9d24ce2357cea5cdd97a"
application_url = "https://doors-grateful-significantly-microsoft.trycloudflare.com"
application_url = "https://hunger-then-murphy-focusing.trycloudflare.com"
embedded = true

[access_scopes]
Expand All @@ -11,10 +11,10 @@ scopes = "write_products"

[auth]
redirect_urls = [
"https://doors-grateful-significantly-microsoft.trycloudflare.com/auth/callback",
"https://doors-grateful-significantly-microsoft.trycloudflare.com/auth/shopify/callback",
"https://doors-grateful-significantly-microsoft.trycloudflare.com/api/auth/callback",
"https://doors-grateful-significantly-microsoft.trycloudflare.com/.shopify/graphiql/auth/callback"
"https://hunger-then-murphy-focusing.trycloudflare.com/auth/callback",
"https://hunger-then-murphy-focusing.trycloudflare.com/auth/shopify/callback",
"https://hunger-then-murphy-focusing.trycloudflare.com/api/auth/callback",
"https://hunger-then-murphy-focusing.trycloudflare.com/.shopify/graphiql/auth/callback"
]

[webhooks]
Expand Down

0 comments on commit cc689c8

Please sign in to comment.