Moved FS proto objects to own file, and MD tutorial

This commit is contained in:
Niklas Jensen
2026-01-17 21:50:11 +01:00
committed by Rune Harlyk
parent a799af360f
commit 485ecb7547
9 changed files with 311 additions and 163 deletions
+7 -7
View File
@@ -1,5 +1,5 @@
import { socket } from '$lib/stores/socket'
import * as Messages from '$lib/platform_shared/message'
import * as FSMessages from '$lib/platform_shared/filesystem'
import type {
FSDeleteRequest,
FSMkdirRequest,
@@ -12,7 +12,7 @@ import type {
FSUploadData,
FSUploadComplete,
FSCancelTransfer
} from '$lib/platform_shared/message'
} from '$lib/platform_shared/filesystem'
const MAX_CHUNK_SIZE = 2 ** 14 // ~= 16 kb
@@ -93,7 +93,7 @@ export class FileSystemClient {
private setupListeners() {
// Listen for download metadata (sent first with file size)
this.metadataListenerCleanup = socket.on(
Messages.FSDownloadMetadata,
FSMessages.FSDownloadMetadata,
(metadata: FSDownloadMetadata) => {
this.handleDownloadMetadata(metadata)
}
@@ -101,7 +101,7 @@ export class FileSystemClient {
// Listen for download data chunks
this.downloadListenerCleanup = socket.on(
Messages.FSDownloadData,
FSMessages.FSDownloadData,
(data: FSDownloadData) => {
this.handleDownloadData(data)
}
@@ -109,7 +109,7 @@ export class FileSystemClient {
// Listen for download completion
this.completeListenerCleanup = socket.on(
Messages.FSDownloadComplete,
FSMessages.FSDownloadComplete,
(complete: FSDownloadComplete) => {
this.handleDownloadComplete(complete)
}
@@ -117,7 +117,7 @@ export class FileSystemClient {
// Listen for upload completion
this.uploadCompleteListenerCleanup = socket.on(
Messages.FSUploadComplete,
FSMessages.FSUploadComplete,
(complete: FSUploadComplete) => {
this.handleUploadComplete(complete)
}
@@ -408,7 +408,7 @@ export class FileSystemClient {
}
// Send chunk as fire-and-forget message
socket.emit(Messages.FSUploadData, uploadData)
socket.emit(FSMessages.FSUploadData, uploadData)
upload.chunksSent++
+8 -1
View File
@@ -7,6 +7,7 @@ import {
type MessageFns
} from '$lib/platform_shared/message'
import * as Messages from '$lib/platform_shared/message'
import { protoMetadata as filesystemProtoMetadata } from '$lib/platform_shared/filesystem'
export const MESSAGE_TYPE_TO_KEY = new Map<MessageFns<unknown>, string>()
export const MESSAGE_TYPE_TO_TAG = new Map<MessageFns<unknown>, number>()
@@ -20,6 +21,12 @@ type PendingRequest = {
timeoutId: ReturnType<typeof setTimeout>
}
// Combine references from both message.proto and filesystem.proto
const combinedReferences: Record<string, MessageFns<unknown>> = {
...protoMetadata.references,
...filesystemProtoMetadata.references
}
const MessageType = protoMetadata.fileDescriptor.messageType?.find(
(msg: { name: string }) => msg.name === 'Message'
)
@@ -27,7 +34,7 @@ const MessageType = protoMetadata.fileDescriptor.messageType?.find(
if (MessageType?.field) {
for (const field of MessageType.field) {
if (field.typeName) {
const messageFns = protoMetadata.references[field.typeName]
const messageFns = combinedReferences[field.typeName]
if (messageFns && field.jsonName && field.number) {
MESSAGE_TYPE_TO_KEY.set(messageFns, field.jsonName)
MESSAGE_TYPE_TO_TAG.set(messageFns, field.number)