MCPcopy Create free account
hub / github.com/blues/note / hubNotefileUpdateNote

Function hubNotefileUpdateNote

lib/hubreq.go:1341–1389  ·  view source on GitHub ↗

Notefile UpdateNote

(ctx context.Context, session *HubSession, req notehubMessage, rsp *notehubMessage, event EventFunc)

Source from the content-addressed store, hash-verified

1339
1340// Notefile UpdateNote
1341func hubNotefileUpdateNote(ctx context.Context, session *HubSession, req notehubMessage, rsp *notehubMessage, event EventFunc) (err error) {
1342 // Open the box
1343 box, ei, _, err2 := openHubNoteboxForDevice(ctx, session, req.DeviceUID, req.DeviceSN, req.ProductUID, req.DeviceEndpointID, event)
1344 if err2 != nil {
1345 err = err2
1346 return
1347 }
1348
1349 // Open the specified notefile
1350 openfile, file, err4 := box.OpenNotefile(ctx, req.NotefileID)
1351 if err4 != nil {
1352 err = err4
1353 box.Close(ctx)
1354 return
1355 }
1356 sawNotefile(session, box, req.NotefileID)
1357
1358 // Perform the operation
1359 xnote, err5 := file.GetNote(req.NoteID)
1360 if err5 != nil {
1361 err = err5
1362 openfile.Close(ctx)
1363 box.Close(ctx)
1364 return
1365 }
1366 var body []byte
1367 ibody, err6 := req.GetBody()
1368 if err6 != nil {
1369 err = err6
1370 } else {
1371 body, err = note.JSONMarshal(ibody)
1372 }
1373 if err == nil {
1374 xnote.SetPayload(req.GetPayload())
1375 err = xnote.SetBody(body)
1376 if err != nil {
1377 err = fmt.Errorf("hubNotefileUpdateNote unable to set note body: %s", err)
1378 }
1379 }
1380 if err == nil {
1381 err = file.UpdateNote(ctx, ei, req.DeviceEndpointID, req.NoteID, xnote)
1382 }
1383
1384 // Done
1385 openfile.Close(ctx)
1386 box.Close(ctx)
1387
1388 return err
1389}
1390
1391// Read a file range, with message fields being used/overloaded as follows:
1392// NotefileIDs is the filename

Callers 1

processRequestFunction · 0.85

Calls 10

openHubNoteboxForDeviceFunction · 0.85
sawNotefileFunction · 0.85
OpenNotefileMethod · 0.80
GetBodyMethod · 0.80
SetPayloadMethod · 0.80
GetPayloadMethod · 0.80
SetBodyMethod · 0.80
CloseMethod · 0.45
GetNoteMethod · 0.45
UpdateNoteMethod · 0.45

Tested by

no test coverage detected