Skip to content

Commit

Permalink
fix(frontend): fix commit process
Browse files Browse the repository at this point in the history
Fixes anydistro#41

- Fixes signature handling in a DnD routine
- Add missing fields indication before the push
  • Loading branch information
LordTermor committed May 26, 2024
1 parent fd694b9 commit c59528b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/src/definitions/package.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ interface IPackageUpload {
name: string;
version?: string;
file: File;
signatureFile?: File;
signatureFile: File;
}
70 changes: 46 additions & 24 deletions frontend/src/pages/FileViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,36 @@ const usePackageDropHandler = (
repository: path[2],
architecture: path[3]
};
const packages: {
[key: string]: Partial<IPackageUpload>;
} = {};
for (const file of acceptedFiles) {
if (file.name.endsWith(".sig")) {
const name = file.name.replace(".sig", "");

packages[name].signatureFile = file;
continue;
}

const packages = acceptedFiles.map((value) => {
return { name: value.name, section, file: value };
});
if (!packages[file.name]) {
packages[file.name] = {
name: file.name,
signatureFile: file.name.endsWith(".sig")
? file
: undefined,
section,
file: file
};
}
}

setCommit({ id: uuid.v4(), section, packages });
setCommit({
id: uuid.v4(),
section,
packages: Object.values(packages)
.filter((partial) => partial as IPackageUpload)
.map((partial) => partial as IPackageUpload)
});
},
[path, setCommit]
);
Expand All @@ -146,31 +170,29 @@ const usePushCommitsHandler = (commits: ICommit[], reload: () => void) => {

let packages = commits.flatMap((value) => value.packages);
packages.forEach((pkg, index) => {
if (pkg.file) {
const missingFields = [];
if (!pkg.file) missingFields.push("package file");
if (!pkg.signatureFile) missingFields.push("signature file");
if (!pkg.section.branch) missingFields.push("branch");
if (!pkg.section.repository) missingFields.push("repository");
if (!pkg.section.architecture)
missingFields.push("architecture");

if (missingFields.length === 0) {
formData.append(`package${index + 1}.filepath`, pkg.file);
}
if (pkg.signatureFile !== undefined) {
formData.append(
`package${index + 1}.signature_path`,
`${pkg.file}.sig`
`package${index + 1}.signature`,
pkg.signatureFile
);
}
if (pkg.section.branch) {
formData.append(
`package${index + 1}.branch`,
pkg.section.branch
);
}
if (pkg.section.repository) {
formData.append(
`package${index + 1}.repository`,
pkg.section.repository
`package${index + 1}`,
JSON.stringify(pkg.section)
);
}
if (pkg.section.architecture) {
formData.append(
`package${index + 1}.architecture`,
pkg.section.architecture
} else {
toast.error(
`Missing package fields for ${
pkg.name
}: ${missingFields.join(", ")}`
);
}
});
Expand Down

0 comments on commit c59528b

Please sign in to comment.