MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / createResource

Method createResource

cmdtools/addnote.cpp:106–145  ·  view source on GitHub ↗

Create a new resource and add it to the database

Source from the content-addressed store, hash-verified

104
105// Create a new resource and add it to the database
106qint32 AddNote::createResource(Resource &r, int sequence, QByteArray data, QString mime, bool attachment, QString filename, qint32 noteLid) {
107 qint32 lid = noteLid;
108 ConfigStore cs(global.db);
109 qint32 rlid = cs.incrementLidCounter();
110
111 QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
112
113 QString guid = QString::number(rlid);
114 NoteTable noteTable(global.db);
115 r.guid = guid;
116 r.noteGuid = noteTable.getGuid(lid);
117 QString noteguid = r.noteGuid;
118 if (noteguid == "")
119 return 0;
120 r.mime = mime;
121 r.active = true;
122 r.updateSequenceNum = sequence;
123 r.width = 0;
124 r.height = 0;
125 r.duration = 0;
126 ResourceAttributes a;
127 if (r.attributes.isSet())
128 a = r.attributes;
129 a.attachment = attachment;
130 if (filename != "") {
131 a.fileName = filename;
132 }
133
134 Data d;
135 d.body = data;
136 d.bodyHash = hash;
137 d.size = data.size();
138
139 r.data = d;
140 r.attributes = a;
141 ResourceTable resourceTable(global.db);
142 resourceTable.add(rlid, r, true, lid);
143
144 return rlid;
145}

Callers 3

addNoteMethod · 0.45
appendNoteMethod · 0.45
addNoteNodeMethod · 0.45

Calls 4

incrementLidCounterMethod · 0.80
getGuidMethod · 0.45
isSetMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected