infra: add linting and formatting for js projects (#230)
* wip * wip * wip * format * wip(mobile): lint and format * cleanup * nits * nits * idiomatic react * nit * format all root files
This commit was merged in pull request #230.
This commit is contained in:
+20
-27
@@ -2,17 +2,17 @@ import {
|
||||
FileSystemUploadType,
|
||||
getInfoAsync,
|
||||
uploadAsync,
|
||||
} from "expo-file-system/legacy";
|
||||
import { apiClient } from "@/api/client";
|
||||
} from 'expo-file-system/legacy';
|
||||
import { apiClient } from '@/api/client';
|
||||
import {
|
||||
createParticle,
|
||||
createStreamParticle,
|
||||
} from "@/lib/firestore-particles";
|
||||
} from '@/lib/firestore-particles';
|
||||
import {
|
||||
particlePath,
|
||||
toFirestoreChildrenPath,
|
||||
type ParticlePath,
|
||||
} from "@/lib/particle-path";
|
||||
} from '@/lib/particle-path';
|
||||
|
||||
interface UploadMediaParticleParams {
|
||||
networkId: string;
|
||||
@@ -21,7 +21,7 @@ interface UploadMediaParticleParams {
|
||||
fileUri: string;
|
||||
mimeType: string;
|
||||
durationMs: number;
|
||||
source: "camera" | "screen";
|
||||
source: 'camera' | 'screen';
|
||||
createdByHumanId: string;
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ export async function uploadMediaParticle({
|
||||
}: UploadMediaParticleParams): Promise<string> {
|
||||
const info = await getInfoAsync(fileUri);
|
||||
if (!info.exists || info.size === undefined) {
|
||||
throw new Error("Recording file disappeared before upload.");
|
||||
throw new Error('Recording file disappeared before upload.');
|
||||
}
|
||||
const sizeBytes = info.size;
|
||||
|
||||
const namePrefix = mimeType.startsWith("audio/") ? "voice" : "video";
|
||||
const namePrefix = mimeType.startsWith('audio/') ? 'voice' : 'video';
|
||||
const ext = extensionFromMime(mimeType);
|
||||
const name = `${namePrefix}-${Date.now()}${ext}`;
|
||||
|
||||
@@ -61,15 +61,13 @@ export async function uploadMediaParticle({
|
||||
});
|
||||
|
||||
const uploadResult = await uploadAsync(upload_url, fileUri, {
|
||||
httpMethod: "PUT",
|
||||
httpMethod: 'PUT',
|
||||
uploadType: FileSystemUploadType.BINARY_CONTENT,
|
||||
headers: upload_headers,
|
||||
});
|
||||
|
||||
if (uploadResult.status < 200 || uploadResult.status >= 300) {
|
||||
throw new Error(
|
||||
`Upload to depot failed (HTTP ${uploadResult.status}).`,
|
||||
);
|
||||
throw new Error(`Upload to depot failed (HTTP ${uploadResult.status}).`);
|
||||
}
|
||||
|
||||
await apiClient.confirmUpload(object_id);
|
||||
@@ -77,7 +75,7 @@ export async function uploadMediaParticle({
|
||||
const collectionPath = toFirestoreChildrenPath(targetPath);
|
||||
return createParticle(
|
||||
collectionPath,
|
||||
"media",
|
||||
'media',
|
||||
{
|
||||
object_id,
|
||||
mime_type: mimeType,
|
||||
@@ -102,20 +100,15 @@ export async function createTextParticle({
|
||||
createdByHumanId,
|
||||
}: CreateTextParticleParams): Promise<string> {
|
||||
const collectionPath = toFirestoreChildrenPath(targetPath);
|
||||
return createParticle(
|
||||
collectionPath,
|
||||
"text",
|
||||
{ content },
|
||||
createdByHumanId,
|
||||
);
|
||||
return createParticle(collectionPath, 'text', { content }, createdByHumanId);
|
||||
}
|
||||
|
||||
function extensionFromMime(mime: string): string {
|
||||
if (mime === "video/mp4") return ".mp4";
|
||||
if (mime === "video/quicktime") return ".mov";
|
||||
if (mime === "audio/mp4") return ".m4a";
|
||||
if (mime === "audio/webm") return ".webm";
|
||||
return "";
|
||||
if (mime === 'video/mp4') return '.mp4';
|
||||
if (mime === 'video/quicktime') return '.mov';
|
||||
if (mime === 'audio/mp4') return '.m4a';
|
||||
if (mime === 'audio/webm') return '.webm';
|
||||
return '';
|
||||
}
|
||||
|
||||
// Helper kept here so callers can construct a fresh stream's child-path before
|
||||
@@ -137,13 +130,13 @@ interface CreateStreamWithFirstParticleParams {
|
||||
createdByHumanId: string;
|
||||
/** First particle to write into the new stream. Required — empty streams are not useful. */
|
||||
firstParticle:
|
||||
| { type: "text"; content: string }
|
||||
| { type: 'text'; content: string }
|
||||
| {
|
||||
type: "media";
|
||||
type: 'media';
|
||||
fileUri: string;
|
||||
mimeType: string;
|
||||
durationMs: number;
|
||||
source: "camera" | "screen";
|
||||
source: 'camera' | 'screen';
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,7 +171,7 @@ export async function createStreamWithFirstParticle({
|
||||
const streamPath = particlePath(networkId, [streamId]);
|
||||
|
||||
// 2. The first child goes inside the new stream.
|
||||
if (firstParticle.type === "text") {
|
||||
if (firstParticle.type === 'text') {
|
||||
await createTextParticle({
|
||||
networkId,
|
||||
targetPath: streamPath,
|
||||
|
||||
Reference in New Issue
Block a user