Skip to content

Commit

Permalink
Merge pull request #514 from BlueBubblesApp/development
Browse files Browse the repository at this point in the history
v1.7.1
  • Loading branch information
zlshames authored Apr 15, 2023
2 parents a16e69a + e2eb39a commit 041d1a0
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluebubbles-server",
"version": "1.7.0",
"version": "1.7.1",
"description": "BlueBubbles Server is the app that powers the BlueBubbles app ecosystem",
"private": true,
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bluebubbles/server",
"version": "1.7.0",
"version": "1.7.1",
"main": "./dist/main.js",
"license": "Apache-2.0",
"author": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { nativeImage } from "electron";
import { getBlurHash } from "@server/helpers/utils";
import { FileSystem } from "@server/fileSystem";
import fs from "fs";
import { getBlurHash, isEmpty } from "@server/helpers/utils";
import { FileSystem } from "@server/fileSystem";
import { Attachment } from "@server/databases/imessage/entity/Attachment";

export class AttachmentInterface {

static livePhotoExts = ["png", "jpeg", "jpg", "heic", "tiff"];

static async getBlurhash({
filePath,
width = null,
Expand Down Expand Up @@ -34,4 +38,26 @@ export class AttachmentInterface {
// Return the name of the attachment
return name;
}

static getLivePhotoPath(attachment: Attachment): string | null {
// If we don't have a path, return null
const fPath = attachment?.filePath;
if (isEmpty(fPath)) return null;

// Get the extension
const ext = fPath.split(".").pop();

// If the extension is not an image extension, return null
if (!AttachmentInterface.livePhotoExts.includes(ext)) return null;

// Get the path to the live photo by replacing the extension with .mov
const livePath = ext !== fPath ? fPath.replace(`.${ext}`, ".mov") : `${fPath}.mov`;
const realPath = FileSystem.getRealPath(livePath);

// If the live photo doesn't exist, return null
if (!fs.existsSync(realPath)) return null;

// If the .mov file exists, return the path
return realPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FileSystem } from "@server/fileSystem";
import { AttachmentResponse } from "@server/types";
import { DEFAULT_ATTACHMENT_CONFIG } from "./constants";
import type { AttachmentSerializerMultiParams, AttachmentSerializerSingleParams } from "./types";
import { AttachmentInterface } from "../interfaces/attachmentInterface";

export class AttachmentSerializer {
static async serialize({
Expand Down Expand Up @@ -105,10 +106,6 @@ export class AttachmentSerializer {
};

if (!isForNotification) {
// Get the path for a possible live photo
const ext = fPath.split(".").pop();
const livePath = ext !== fPath ? fPath.replace(`.${ext}`, ".mov") : `${fPath}.mov`;

output = {
...output,
...{
Expand All @@ -117,7 +114,7 @@ export class AttachmentSerializer {
hideAttachment: attachment.hideAttachment,
isSticker: attachment.isSticker,
originalGuid: attachment.originalGuid,
hasLivePhoto: !fPath.endsWith('.mov') && fs.existsSync(livePath)
hasLivePhoto: !!AttachmentInterface.getLivePhotoPath(attachment)
}
};
}
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,11 @@ class BlueBubblesServer extends EventEmitter {
}
}

// If the password changes, we need to make sure the clients connected to the socket are kicked.
if (prevConfig.password !== nextConfig.password) {
this.httpService.kickClients();
}

this.emitToUI("config-update", nextConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Server } from "@server";
import { generateMd5Hash } from "@server/utils/CryptoUtils";
import { FileSystem } from "@server/fileSystem";
import { convertAudio, convertImage } from "@server/databases/imessage/helpers/utils";
import { isTruthyBool } from "@server/helpers/utils";
import { isEmpty, isTruthyBool } from "@server/helpers/utils";
import { AttachmentInterface } from "@server/api/v1/interfaces/attachmentInterface";
import { FileStream, Success } from "../responses/success";
import { NotFound, ServerError } from "../responses/errors";
Expand Down Expand Up @@ -104,18 +104,16 @@ export class AttachmentRouter {

// Fetch the info for the attachment by GUID
const attachment = await Server().iMessageRepo.getAttachment(guid);
if (!attachment) throw new NotFound({ error: "Attachment does not exist!" });
if (!attachment || isEmpty(attachment.filePath)) throw new NotFound({ error: "Attachment does not exist!" });

const aPath = FileSystem.getRealPath(attachment.filePath);
if (!fs.existsSync(aPath)) throw new NotFound({ error: "Attachment does not exist in disk!" });

// Replace the extension with .mov (if there is one). Otherwise just append .mov
const ext = aPath.split(".").pop();
const livePath = ext !== aPath ? aPath.replace(`.${ext}`, ".mov") : `${aPath}.mov`;
if (aPath.endsWith('.mov') || !fs.existsSync(livePath))
throw new NotFound({ error: "Live photo does not exist for this attachment!" });
const livePhotoPath = AttachmentInterface.getLivePhotoPath(attachment);
if (!livePhotoPath) throw new NotFound({ error: "Live photo does not exist for this attachment!" });

return new FileStream(ctx, livePath, "video/quicktime").send();
return new FileStream(ctx, livePhotoPath, "video/quicktime").send();
}

static async blurhash(ctx: RouterContext, _: Next) {
Expand Down
10 changes: 9 additions & 1 deletion packages/server/src/server/services/httpService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export class HttpService {
jsonLimit: "100mb",
textLimit: "100mb",
formLimit: "1000mb",
multipart: true
multipart: true,
parsedMethods: ['POST', 'PUT', 'PATCH', 'DELETE']
})
);

Expand Down Expand Up @@ -251,6 +252,13 @@ export class HttpService {
});
}

kickClients() {
if (!this.socketServer) return;
this.socketServer.sockets.sockets.forEach(socket => {
socket.disconnect();
});
}

async stop(): Promise<void> {
Server().log("Stopping HTTP Service...");

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bluebubbles/ui",
"version": "1.7.0",
"version": "1.7.1",
"homepage": "./",
"license": "Apache-2.0",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ export const ConnectionSettings = (): JSX.Element => {
<LocalPortField />

<Spacer />
<Accordion allowMultiple>
<AccordionItem>
<AccordionButton>
<Box flex='1' textAlign='left' width="15em">
Advanced Connection Settings
</Box>
<AccordionIcon />
</AccordionButton>
<AccordionPanel pb={4}>
{/* <EncryptCommunicationsField />
<Box m={15} /> */}
{(proxyService === 'dynamic-dns') ? (<UseHttpsField />) : null}
</AccordionPanel>
</AccordionItem>
</Accordion>
{(proxyService === 'dynamic-dns') ? (
<Accordion allowMultiple>
<AccordionItem>
<AccordionButton>
<Box flex='1' textAlign='left' width="15em">
Advanced Connection Settings
</Box>
<AccordionIcon />
</AccordionButton>
<AccordionPanel pb={4}>
{/* <EncryptCommunicationsField />
<Box m={15} /> */}
<UseHttpsField />
</AccordionPanel>
</AccordionItem>
</Accordion>
) : null}
</Stack>
);
};

0 comments on commit 041d1a0

Please # to comment.