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

Update to v5 beta.16 #2

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

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update to v5 beta.16
  • Loading branch information
maccomaccomaccomacco committed Jun 25, 2024
commit dd82ad3821d4229855cf1090668b5d6794a4e88c
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"dependencies": {
"@strapi/plugin-graphql": "^4.0.5",
"@strapi/plugin-graphql": "5.0.0-beta.14",
"fs-extra": "^10.0.0",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27",
"@strapi/strapi": "4.21.1",
"@strapi/plugin-users-permissions": "4.21.1",
"@strapi/plugin-i18n": "4.21.1",
"@strapi/plugin-cloud": "4.21.1",
"better-sqlite3": "8.6.0",
"@strapi/plugin-cloud": "5.0.0-beta.16",
"@strapi/plugin-users-permissions": "5.0.0-beta.16",
"@strapi/strapi": "5.0.0-beta.14",
"better-sqlite3": "9.4.3",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "5.3.4",
"styled-components": "5.3.3"
"react-router-dom": "^6.0.0",
"styled-components": "^6.0.0"
},
"name": "my-app-name",
"private": true,
Expand Down
Empty file removed public/uploads/.gitkeep
Empty file.
53 changes: 28 additions & 25 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";

const os = require("os");
const fs = require("fs-extra");
const path = require("path");
const mime = require("mime-types");
Expand Down Expand Up @@ -58,16 +58,17 @@ function getFileSizeInBytes(filePath) {

function getFileData(fileName) {
const filePath = path.join("data", "uploads", fileName);
// Parse the file metadata
const size = getFileSizeInBytes(filePath);
const ext = fileName.split(".").pop();
const size = fs.statSync(filePath)["size"];
const ext = filePath.split(".").pop();
const mimeType = mime.lookup(ext);

return {
path: filePath,
name: fileName,
size,
filepath: path.resolve(filePath),
originalFilename: fileName,
type: mimeType,
mimetype: mimeType,
ext,
size,
};
}

Expand All @@ -87,15 +88,16 @@ async function uploadFile(file, name) {
});
}

// Create an entry and attach files if there are any
async function createEntry({ model, entry }) {

async function createDocument({ model, document }) {
try {
// Actually create the entry in Strapi
await strapi.entityService.create(`api::${model}.${model}`, {
data: entry,
await strapi.documents(model).create({
data: document,
status: "published",
});
} catch (error) {
console.error({ model, entry, error });
console.error({ model, document, error });
}
}

Expand Down Expand Up @@ -163,14 +165,15 @@ async function importArticles() {
const cover = await checkFileExistsBeforeUpload([`${article.slug}.jpg`]);
const updatedBlocks = await updateBlocks(article.blocks);

await createEntry({
model: "article",
entry: {
await createDocument({
model: "api::article.article",
document: {
...article,
cover,
blocks: updatedBlocks,
// Make sure it's not a draft
publishedAt: Date.now(),
status: "published"
},
});
}
Expand All @@ -179,9 +182,9 @@ async function importArticles() {
async function importGlobal() {
const favicon = await checkFileExistsBeforeUpload(["favicon.png"]);
const shareImage = await checkFileExistsBeforeUpload(["default-image.png"])
return createEntry({
model: "global",
entry: {
return createDocument({
model: "api::global.global",
document: {
...global,
favicon,
// Make sure it's not a draft
Expand All @@ -197,9 +200,9 @@ async function importGlobal() {
async function importAbout() {
const updatedBlocks = await updateBlocks(about.blocks);

await createEntry({
model: "about",
entry: {
await createDocument({
model: "api::about.about",
document: {
...about,
blocks: updatedBlocks,
// Make sure it's not a draft
Expand All @@ -210,17 +213,17 @@ async function importAbout() {

async function importCategories() {
for (const category of categories) {
await createEntry({ model: "category", entry: category });
await createDocument({ model: "api::category.category", document: category });
}
}

async function importAuthors() {
for (const author of authors) {
const avatar = await checkFileExistsBeforeUpload([author.avatar]);

await createEntry({
model: "author",
entry: {
await createDocument({
model: "api::author.author",
document: {
...author,
avatar,
},
Expand Down
Loading