Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from Flowko/adding-folder-structure-for-multip…
Browse files Browse the repository at this point in the history
…le-images-generation

⛏️ added same URL original structure option top multiple urls option
  • Loading branch information
Flowko authored Jun 19, 2022
2 parents 9b37394 + 903cc6e commit cba0ac6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
39 changes: 37 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
class="border !border-red-500"
></b-button>
</div>
<b-field>
<b-checkbox type="is-info" v-model="params.keepUrlStructure">
Use Same URL Original Structure
<b-tooltip type="is-success is-dark" position="is-bottom">
<template v-slot:content>
<div class="text-base">
<b>Unchecked:</b> Saves screenshots of all pages in the same
parent folder.
<br />
<b>Checked:</b> Saves screenshots of all pages in their own
folders.
</div>
</template>
<b-icon
type="is-success"
icon="information-outline"
size="is-small"
>
</b-icon>
</b-tooltip>
</b-checkbox>
</b-field>
</div>

<div class="s-grid">
Expand Down Expand Up @@ -463,7 +485,6 @@
@click="generateScreenshot"
type="is-info"
class="border !border-primary-100"
:disabled="loading || !params.url"
>Capture Screenshot</b-button
>
</div>
Expand Down Expand Up @@ -544,6 +565,7 @@ export default {
url: null,
},
],
keepUrlStructure: false,
},
imageFormats: ["png", "jpeg", "webp"],
pdfFile: null,
Expand Down Expand Up @@ -659,12 +681,17 @@ export default {
"Letter",
"Legal",
],
disableBtn: true,
};
},
mounted() {},
methods: {
async generateScreenshot() {
if (!this.loading && this.params.url !== null) {
if (
this.selectedType == "multiple-imgs" ||
!this.loading ||
this.params.url !== null
) {
this.loading = true;
this.result = {
url: null,
Expand Down Expand Up @@ -755,6 +782,14 @@ export default {
"params.height"() {
this.params.size = `${this.params.width}x${this.params.height}`;
},
selectedType() {
this.params.url = null;
this.params.urls = [
{
url: null,
},
];
},
},
};
</script>
16 changes: 12 additions & 4 deletions server-middleware/website-shot.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ CustomBufferBuilder.prototype.getBuffer = function () {
app.post("/screenshot", async (req, res) => {
const params = req.body;

if (params.url) {
if (
params &&
((params.type == "multiple-imgs" && params.urls[0].url != null) ||
params.url != null)
) {
const styles = [];
const scripts = [];

Expand Down Expand Up @@ -153,15 +157,19 @@ app.post("/screenshot", async (req, res) => {
// const { requestUrl } = await got.head(site);
// return requestUrl;

console.log(filename);

await captureWebsite
.buffer(site.url, options)
.then(async (buffer) => {
var customBufferBuilder = new CustomBufferBuilder();
customBufferBuilder.append(buffer);
var bufferContent = customBufferBuilder.getBuffer();
await zip.file(filename, bufferContent, { binary: true });
var newFilename = !params.keepUrlStructure
? filename
: filename.replaceAll("!", "/");
await zip.file(newFilename, bufferContent, {
binary: true,
createFolders: true,
});
})
.catch((error) => {
console.log(error);
Expand Down

0 comments on commit cba0ac6

Please sign in to comment.