jsgui3-server 0.0.121 → 0.0.123

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/.vscode/settings.json +6 -0
  2. package/README.md +10 -10
  3. package/controls/Active_HTML_Document.js +116 -116
  4. package/controls/README.md +7 -7
  5. package/controls/page/admin.js +74 -74
  6. package/controls/panel/admin.js +11 -11
  7. package/examples/_css/basic.css +913 -913
  8. package/examples/_css/database-control.css +51 -51
  9. package/examples/_css/jsgui.css +66 -66
  10. package/examples/_css/multi-layout.css +23 -23
  11. package/examples/_css/style.css +1669 -1669
  12. package/examples/_css/top-and-bottom-bars.css +54 -54
  13. package/examples/box/1) square box/client.js +188 -188
  14. package/examples/box/1) square box/server.js +112 -112
  15. package/examples/box/2) twenty square boxes/css flex wrap/client.js +112 -248
  16. package/examples/box/2) twenty square boxes/css flex wrap/server.js +39 -112
  17. package/examples/box/3) twenty selectable square boxes/css flex wrap/client.js +129 -0
  18. package/examples/{controls/15) window, text field → box/3) twenty selectable square boxes/css flex wrap}/server.js +38 -38
  19. package/examples/boxes/square_boxes.js +45 -48
  20. package/examples/boxes/square_boxes_client.js +132 -136
  21. package/examples/client-side-popup-menu-button.html +93 -93
  22. package/examples/color_palette.js +51 -51
  23. package/examples/color_palette_client.js +95 -95
  24. package/examples/controls/1) window/client.js +186 -186
  25. package/examples/controls/1) window/server.js +117 -117
  26. package/examples/controls/10) window, mirrored text inputs/client.js +118 -320
  27. package/examples/controls/10) window, mirrored text inputs/server.js +37 -117
  28. package/examples/controls/11) window, mirrored text fields/client.js +493 -251
  29. package/examples/controls/11) window, mirrored text fields/server.js +117 -117
  30. package/examples/controls/11b) window, shared Data_Object model mirrored text fields/client.js +613 -331
  31. package/examples/controls/11b) window, shared Data_Object model mirrored text fields/server.js +117 -117
  32. package/examples/controls/11c) window, shared Data_Value model mirrored text fields/client.js +617 -617
  33. package/examples/controls/11c) window, shared Data_Value model mirrored text fields/server.js +117 -117
  34. package/examples/controls/11d) window, shared model mirrored integer text fields/client.js +611 -280
  35. package/examples/controls/11d) window, shared model mirrored integer text fields/server.js +134 -22
  36. package/examples/controls/12) window, Select_Options control/client.js +66 -452
  37. package/examples/controls/12) window, Select_Options control/server.js +19 -117
  38. package/examples/controls/13) window, Dropdown_Menu control/client.js +66 -0
  39. package/examples/controls/13) window, Dropdown_Menu control/server.js +20 -0
  40. package/examples/controls/2) two windows/client.js +193 -193
  41. package/examples/controls/2) two windows/server.js +113 -113
  42. package/examples/controls/3) five windows/client.js +217 -217
  43. package/examples/controls/3) five windows/server.js +116 -115
  44. package/examples/controls/4) window, tabbed panel/client.js +54 -225
  45. package/examples/controls/4) window, tabbed panel/server.js +17 -117
  46. package/examples/controls/5) window, grid/client.js +204 -484
  47. package/examples/controls/5) window, grid/server.js +117 -119
  48. package/examples/controls/6) window, color_palette/client.js +68 -204
  49. package/examples/controls/6) window, color_palette/server.js +117 -117
  50. package/examples/controls/7) window, month_view/client.js +40 -231
  51. package/examples/controls/7) window, month_view/server.js +117 -117
  52. package/examples/controls/8) window, checkbox/client.js +33 -209
  53. package/examples/controls/8) window, checkbox/server.js +117 -117
  54. package/examples/controls/9) window, date picker/client.js +76 -303
  55. package/examples/controls/9) window, date picker/server.js +117 -117
  56. package/examples/controls/9b) window, shared data.model mirrored date pickers/README.md +51 -0
  57. package/examples/controls/9b) window, shared data.model mirrored date pickers/client.js +83 -398
  58. package/examples/controls/9b) window, shared data.model mirrored date pickers/server.js +117 -117
  59. package/examples/controls/__old/_html-server-color-palette.js +114 -114
  60. package/examples/controls/__old/html-server-combo-box.js +104 -104
  61. package/examples/controls/__old/html-server-list.js +98 -98
  62. package/examples/controls/__old/html-server-popup-menu-button.js +114 -114
  63. package/examples/controls/__old/html-server-start-stop-toggle-button.js +146 -146
  64. package/examples/controls/__old/scs-arrow-button.js +36 -36
  65. package/examples/controls/__old/scs-date-picker.js +157 -157
  66. package/examples/controls/__old/scs-file-browser.js +82 -82
  67. package/examples/controls/__old/scs-item.js +159 -159
  68. package/examples/controls/__old/scs-month-arrow-selector.js +126 -126
  69. package/examples/controls/__old/scs-month-view.js +94 -94
  70. package/examples/controls/__old/scs-start-stop-toggle-button.js +40 -40
  71. package/examples/controls/__old/scs-tree.js +49 -49
  72. package/examples/controls/__old/scs-year-arrow-selector.js +127 -127
  73. package/examples/demos/date-picker.js +119 -119
  74. package/examples/demos/explain-encapsulation.js +9 -9
  75. package/examples/demos/resizing.js +35 -35
  76. package/examples/demos/server_time.js +6 -6
  77. package/examples/grids/grid_1.js +45 -45
  78. package/examples/grids/grid_1_client.js +329 -329
  79. package/examples/html-rendering.js +20 -20
  80. package/examples/html-server.js +105 -105
  81. package/examples/introducing jsgui3/server.js +110 -110
  82. package/examples/mx_display/mx_display_1.js +45 -45
  83. package/examples/mx_display/mx_display_1_client.js +444 -444
  84. package/fs2.js +1836 -1836
  85. package/http/responders/HTTP_Responder.js +15 -15
  86. package/http/responders/static/Static_Route_HTTP_Responder.js +105 -105
  87. package/module.js +34 -34
  88. package/old/_single-control-server.js +418 -418
  89. package/old/single-control-server.js +368 -368
  90. package/old/single-page-app.js +131 -131
  91. package/package.json +42 -42
  92. package/page-context.js +92 -92
  93. package/publishers/helpers/assigners/Assigner.js +10 -10
  94. package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -150
  95. package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +109 -109
  96. package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +91 -91
  97. package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -104
  98. package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +18 -18
  99. package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +44 -44
  100. package/publishers/http-function-publisher.js +212 -212
  101. package/publishers/http-html-page-publisher.js +5 -5
  102. package/publishers/http-html-publisher.js +24 -24
  103. package/publishers/http-js-publisher.js +135 -135
  104. package/publishers/http-observable-publisher.js +124 -124
  105. package/publishers/http-publisher.js +53 -53
  106. package/publishers/http-resource-publisher.js +325 -325
  107. package/publishers/http-webpage-publisher.js +659 -658
  108. package/publishers/http-webpageorsite-publisher.js +343 -343
  109. package/publishers/http-website-publisher.js +640 -640
  110. package/publishers/notes.md +9 -9
  111. package/resources/README.md +16 -16
  112. package/resources/_old_website-javascript-resource.js +994 -994
  113. package/resources/_old_website-resource.js +507 -507
  114. package/resources/compile/server-resource-compilation.js +43 -43
  115. package/resources/data-resource.js +118 -118
  116. package/resources/fs-resource.js +146 -146
  117. package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -105
  118. package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +42 -42
  119. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +61 -61
  120. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +41 -41
  121. package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +61 -61
  122. package/resources/jsbuilder/JS_AST/JS_AST_Node.js +93 -93
  123. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +253 -253
  124. package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +337 -337
  125. package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +39 -39
  126. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +96 -96
  127. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +37 -37
  128. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +61 -61
  129. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +43 -43
  130. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +72 -72
  131. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +92 -92
  132. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -29
  133. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -116
  134. package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +159 -159
  135. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +178 -178
  136. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +87 -87
  137. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +91 -91
  138. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +136 -136
  139. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +73 -73
  140. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +39 -39
  141. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +85 -85
  142. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +42 -42
  143. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +40 -40
  144. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +54 -54
  145. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +45 -45
  146. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +343 -343
  147. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +38 -38
  148. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +30 -30
  149. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +28 -28
  150. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +26 -26
  151. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +8 -8
  152. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +43 -43
  153. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +21 -21
  154. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +89 -89
  155. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +8 -8
  156. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +27 -27
  157. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +28 -28
  158. package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +736 -736
  159. package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +64 -64
  160. package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +31 -31
  161. package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -15
  162. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +305 -305
  163. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +77 -77
  164. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +248 -248
  165. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +138 -138
  166. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -10
  167. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +100 -100
  168. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +60 -60
  169. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +179 -179
  170. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -43
  171. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -12
  172. package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -35
  173. package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -11
  174. package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +31 -31
  175. package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +37 -37
  176. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +39 -39
  177. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -25
  178. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +200 -200
  179. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +43 -43
  180. package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +76 -76
  181. package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +227 -227
  182. package/resources/jsbuilder/JS_AST/query/find_object_keys.js +404 -404
  183. package/resources/jsbuilder/JS_AST/query/node_queries.js +8 -8
  184. package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +11 -11
  185. package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +85 -85
  186. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +123 -123
  187. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +87 -87
  188. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +10 -10
  189. package/resources/jsbuilder/JS_Builder.js +10 -10
  190. package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +31 -31
  191. package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +25 -25
  192. package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +78 -78
  193. package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +17 -17
  194. package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +25 -25
  195. package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +8 -8
  196. package/resources/jsbuilder/JS_File/JS_File.js +12 -12
  197. package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -202
  198. package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -175
  199. package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -81
  200. package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -86
  201. package/resources/jsbuilder/JS_File/JS_File_4-Query.js +413 -413
  202. package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +414 -414
  203. package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -59
  204. package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -24
  205. package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -12
  206. package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +23 -23
  207. package/resources/jsbuilder/JS_File/JS_File_Import_References.js +31 -31
  208. package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -16
  209. package/resources/jsbuilder/JS_File/JS_Files.js +15 -15
  210. package/resources/jsbuilder/Module.js +14 -14
  211. package/resources/jsbuilder/Platform.js +13 -13
  212. package/resources/jsbuilder/Platforms.js +69 -69
  213. package/resources/jsbuilder/Project.js +109 -109
  214. package/resources/jsbuilder/Reference.js +1 -1
  215. package/resources/jsbuilder/Reference_Sequence.js +16 -16
  216. package/resources/jsbuilder/Scope.js +29 -29
  217. package/resources/jsbuilder/Variable_Name_Provider.js +42 -42
  218. package/resources/jsbuilder/_JS_File.js +225 -225
  219. package/resources/jsbuilder/ast_query.js +20 -20
  220. package/resources/jsbuilder/babel/babel_consts.js +162 -162
  221. package/resources/jsbuilder/babel/babel_node_tools.js +541 -541
  222. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +923 -904
  223. package/resources/jsbuilder/build.js +16 -16
  224. package/resources/jsbuilder/platform_notes.md +66 -66
  225. package/resources/jsbuilder/test/test_ast_node.js +381 -381
  226. package/resources/jsbuilder/test/test_js_file.js +303 -303
  227. package/resources/jsbuilder/test/test_project.js +157 -157
  228. package/resources/local-server-info-resource.js +96 -96
  229. package/resources/notes.txt +10 -10
  230. package/resources/old/website-image-resource.js +1185 -1185
  231. package/resources/process-js.js +498 -498
  232. package/resources/processors/bundlers/bundle.js +29 -29
  233. package/resources/processors/bundlers/bundler.js +23 -23
  234. package/resources/processors/bundlers/css-bundler.js +234 -234
  235. package/resources/processors/bundlers/js/JS_Bundler.js +51 -51
  236. package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +388 -391
  237. package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +8 -8
  238. package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +188 -188
  239. package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -192
  240. package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +239 -239
  241. package/resources/processors/bundlers/js-bundler.js +263 -263
  242. package/resources/processors/bundlers/test_ast.js +73 -73
  243. package/resources/processors/bundlers/webpage-bundler.js +404 -404
  244. package/resources/processors/bundlers/website-bundler.js +22 -22
  245. package/resources/processors/extractors/Extractor.js +9 -11
  246. package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -254
  247. package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +3 -3
  248. package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +93 -93
  249. package/resources/server-installed-tools.js +28 -28
  250. package/resources/server-resource-pool.js +41 -41
  251. package/resources/website-audio-resource.js +735 -735
  252. package/resources/website-css-resource.js +411 -411
  253. package/resources/website-image-resource.js +412 -412
  254. package/resources/website-javascript-resource-processor.js +908 -908
  255. package/resources/website-javascript-resource.js +874 -874
  256. package/resources/website-resource-processor.js +10 -10
  257. package/resources/website-resource.js +164 -164
  258. package/resources/website-static-html-resource.js +199 -199
  259. package/resources/website-template-html-resource.js +231 -231
  260. package/roadmap.md +75 -75
  261. package/server.js +609 -573
  262. package/static-page-context.js +13 -13
  263. package/website/webpage.js +81 -81
  264. package/website/website-group.js +15 -15
  265. package/website/website.js +260 -260
  266. package/examples/controls/11d) window, shared model mirrored integer text fields/both.js +0 -17
  267. package/examples/controls/13) window, shared model mirrored lat_long/client.js +0 -933
  268. package/examples/controls/13) window, shared model mirrored lat_long/server.js +0 -50
  269. package/examples/controls/14) window, control compositional model/client.js +0 -328
  270. package/examples/controls/14) window, control compositional model/server.js +0 -118
  271. package/examples/controls/14a) window, control spec has compositional model/client.js +0 -440
  272. package/examples/controls/14a) window, control spec has compositional model/server.js +0 -118
  273. package/examples/controls/15) window, text field/client.js +0 -256
  274. package/examples/controls/16) Window([Text_Input])/client.js +0 -266
  275. package/examples/controls/16) Window([Text_Input])/server.js +0 -109
  276. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/client.js +0 -494
  277. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/isomorphic.js +0 -24
  278. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/server.js +0 -73
  279. package/examples/controls/2b) two window, context menus/client.js +0 -193
  280. package/examples/controls/2b) two window, context menus/server.js +0 -114
  281. package/examples/controls/4a) window, tabbed panel with various controls inside/client.js +0 -233
  282. package/examples/controls/4a) window, tabbed panel with various controls inside/server.js +0 -118
@@ -1,1186 +1,1186 @@
1
- /*
2
- if (typeof define !== 'function') {
3
- var define = require('amdefine')(module);
4
- }
5
-
6
- define(['module', 'path', 'fs', 'url', '../../web/jsgui-html', 'os', 'http', 'url', './resource',
7
- '../../web/jsgui-je-suis-xml', 'cookies', '../../fs/jsgui-node-fs2-core',
8
- //"jpeg-js",
9
- '../../image/node/jsgui-node-jpeg',
10
- '../../image/node/jsgui-node-png',
11
- 'webworker-threads'],
12
-
13
- function(module, path, fs, url, jsgui, os, http, libUrl,
14
- Resource, JeSuisXML, Cookies, fs2,
15
- jsgui_jpeg,
16
- jsgui_png,
17
- Worker) {
18
- */
19
-
20
-
21
- // 24/07/2019 - Looks like this needs more work.
22
- // Want to provide simple and powerful API.
23
-
24
- // Specifically being able to deal with icons and a directory of icons.
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
- var path = require('path'),
33
- fs = require('fs'),
34
- url = require('url'),
35
- jsgui = require('jsgui3-html'),
36
- os = require('os'),
37
- http = require('http'),
38
- libUrl = require('url'),
39
- Resource = jsgui.Resource;
40
-
41
- fs2 = require('../fs2');
42
-
43
- // Then could this connect to a cms db?
44
- // Or a wider source of images?
45
- // Mapping the ws image requests to acquiring the image data.
46
- // Won't necessarily be on disk. Could call to another resource, such as network / file / files on network.
47
- // Could map over / use another resource.
48
-
49
- /*
50
-
51
- jsgui_jpeg = require('../../image/node/jsgui-node-jpeg'),
52
- jsgui_png = require('../../image/node/jsgui-node-png');
53
-
54
-
55
- */
56
- //Worker = require('webworker-threads');
57
-
58
- var stringify = jsgui.stringify,
59
- each = jsgui.eac,
60
- arrayify = jsgui.arrayify,
61
- tof = jsgui.tof;
62
- var call_multi = jsgui.call_multi;
63
- var filter_map_by_regex = jsgui.filter_map_by_regex;
64
- var Class = jsgui.Class,
65
- Data_Object = jsgui.Data_Object,
66
- Enhanced_Data_Object = jsgui.Enhanced_Data_Object;
67
- var fp = jsgui.fp,
68
- is_defined = jsgui.is_defined;
69
- var get_item_sig = jsgui.get_item_sig;
70
- var Collection = jsgui.Collection;
71
-
72
- // This resource may have quite a lot of functionality put in to deal with
73
- // seriving images in an optimized way.
74
- // Want this so it also serves the developer in that images can be put in place
75
- // and modified easily in an unoptimized way. Then they get put in place in an
76
- // optimized way on request or automatically. Want to incorporate sprite sheet generation
77
- // here. This should handle requests for individual images, but it's also possible sprites
78
- // could be requested. If that's the case, maybe it should pass it onto a sprite resource.
79
- // It would be really good to have practically instant sprite generation, using C / C++
80
- // and maybe OpenCL.
81
- // It could be requests to a sprite resource that returns a predefined selection of
82
- // assets.
83
- // The image resource may also be called upon to return rescaled versions.
84
- // That's something that OpenCL would also be very fast at.
85
- // The image / spritesheet resources may be connected to other database resources that provide
86
- // caching and indexing of images.
87
- // These would most likely be abstractions over data resources.
88
-
89
- // Want to make an image interface to a flexible db interface.
90
- // Serving and caching optimized images would be cool.
91
-
92
- // Rather than relying on storing image versions in a DB (which would be cool, esp for distributed)
93
- // we can store image versions + spritesheets on the local disk.
94
- // Cache them in RAM as well.
95
- // Storing them in GPU RAM would be very cool, especially if from there we can get versions with
96
- // different operations done, or the output of operations.
97
-
98
-
99
- // May need to change around a fair few references to make it workable.
100
- // May need some more complicated logic to change it to the path for service.
101
-
102
-
103
-
104
- // This is going to be extended so that it works with the Web_DB_Resource system.
105
-
106
- // Will have further handling on images, hopefully just deal with the DB side of things as file storage.
107
- // Will keep image processing algorithms (and probably calls) out of the Web_DB_Postgres module, but use that interface
108
- // to interact with images.
109
-
110
- // This module should also be comfortable dealing with images from the file system.
111
-
112
- // Also want to be able to quickly get thumbnails of images.
113
-
114
- // Will refer to images by a 'key', and also specify a size to get / display the image at
115
- // The point will be to make it easy to program the appearance of the image, not having to keep track of the URL, having the image
116
- // within a convenient admin system.
117
-
118
- // Serving a thumbnail, based on the image key, makes the most sense.
119
-
120
- // Want to be able to get the URL for an image from the key.
121
- // Will also be able to get thumbnail URLs.
122
-
123
- // I think this Resource will also have more specialised functionality, possibly handlers too, that will be used by other modules.
124
-
125
- // Add an image to the database, along with it's metadata, and thumbnail versions.
126
- // Thumbnail versions under key _400x300
127
- // I think x will be an OK separator here.
128
- // That size will refer to their maximum dimensions.
129
-
130
-
131
-
132
-
133
- // need to see what type of image it is.
134
- var mime_types = {
135
- 'jpg': 'image/jpeg',
136
- 'jpeg': 'image/jpeg',
137
- 'gif': 'image/gif',
138
- 'png': 'image/png',
139
- 'svg': 'image/svg+xml',
140
- 'otf': 'application/font-sfnt',
141
- 'ttf': 'application/font-sfnt'
142
- }
143
-
144
- var serve_image_file_from_buffer = function (buffer, filename, response) {
145
- console.log('filename', filename);
146
- var extname = path.extname(filename);
147
- console.log('extname ' + extname);
148
-
149
- var extension = extname.substr(1);
150
- console.log('extension ' + extension);
151
-
152
- response.writeHead(200, {
153
- 'Content-Type': mime_types[extension]
154
- });
155
- response.end(buffer, 'binary');
156
- }
157
-
158
-
159
- var serve_image_file_from_disk = function (filePath, response) {
160
- var extname = path.extname(filePath);
161
- console.log('extname ' + extname);
162
- var extension = extname.substr(1);
163
- console.log('extension ' + extension);
164
-
165
- // then return the right MIME type for that extension.
166
-
167
- // No, don't load the image file as a string.
168
-
169
- // fs loadfile
170
- // async, then serve it with the correct mime type, write to the response buffer.
171
-
172
- // can this be streamed to the response buffer?
173
-
174
- fs.readFile(filePath, function (err, data) {
175
- if (err) {
176
- throw err;
177
- } else {
178
- response.writeHead(200, {
179
- 'Content-Type': mime_types[extension]
180
- });
181
- response.end(data, 'binary');
182
- }
183
- });
184
-
185
-
186
- //fs2.load_file_as_string(filePath, function (err, data) {
187
- // if (err) {
188
- // throw err;
189
- // } else {
190
- // //var servableJs = updateReferencesForServing(data);
191
- // response.writeHead(200, {'Content-Type': mime_types[extension]});
192
- // response.end(data);
193
- // }
194
- //});
195
- }
196
-
197
-
198
- class Site_Images extends Resource {
199
-
200
-
201
- constructor(spec) {
202
- super(spec);
203
-
204
- //this.meta.set('custom_paths', new Data_Object({}));
205
-
206
- //this.custom_paths = new Data_Object({});
207
- this.custom_paths = {};
208
-
209
-
210
- // Those are custom file paths.
211
-
212
- // could have a collection of directories, indexed by name, that get served.
213
-
214
- // Index the collection by string value?
215
- //this.meta.set('served_directories', new Collection({'index_by': 'name'}));
216
- this.served_directories = new Collection({
217
- 'index_by': 'name'
218
- });
219
-
220
- }
221
- 'start'(callback) {
222
- callback(null, true);
223
- }
224
- 'get_image_url'(image_key) {
225
-
226
- }
227
- 'get_icon_url'(icon_key) {
228
- // May have different size icons
229
- // For the moment will keep this simple.
230
-
231
- return '/img/icons/' + icon_key + '.png';
232
-
233
-
234
- }
235
-
236
-
237
- /*
238
- 'get_metadata': fp(function(a, sig) {
239
- console.log('get_metadata sig', sig);
240
-
241
- var value, type_name, callback;
242
- if (sig == '[B,s,f]') {
243
- value = a[0]; type_name = a[1]; callback = a[2];
244
-
245
- if (type_name === 'jpeg') {
246
-
247
- // do this in a web worker?
248
- //console.log('pre run web worker')
249
-
250
-
251
- //var worker = new Worker.Worker(function() {
252
- //console.log('running web worker')
253
- ////postMessage("I'm working before postMessage('ali').");
254
- ////this.onmessage = function(event) {
255
- //// But does the worker have access to jpeg_js?
256
- //console.log('pre decode');
257
- //var decoded = jpeg_js.decode(value);
258
- //console.log('post decode');
259
- //var width = decoded.width;
260
- //var height = decoded.height;
261
- //var res = {
262
- //'width': width,
263
- //'height': height,
264
- //'type_name': type_name
265
- //}
266
- //callback(null, res);
267
- //postMessage(res);
268
- //worker.close();
269
- //});
270
- //worker.onmessage = function(event) {
271
- //console.log("Worker said : " + event.data);
272
- //};
273
-
274
-
275
-
276
- // It would be nice to improve the speed of the JPEG_JS module.
277
-
278
- var jpeg = new jsgui_jpeg.JPEG({});
279
-
280
- // load_size_from_buffer
281
-
282
-
283
-
284
-
285
- jpeg.load_size_from_buffer(value, function(err, size) {
286
- if (err) {
287
- // But if there was an error loading the JPEG, it needs to raise an error.
288
- // I'm now going to use
289
-
290
-
291
- throw err;
292
-
293
- } else {
294
-
295
-
296
- //console.log('jpeg loaded');
297
-
298
- //console.log('size', size);
299
-
300
- //throw 'stop';
301
-
302
- callback(null, {
303
- 'size': size
304
- });
305
-
306
-
307
-
308
- }
309
- })
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
- }
318
- }
319
- }),
320
- */
321
-
322
- /*
323
-
324
- '__get_resized_versions': fp(function(a, sig) {
325
-
326
- // No, this needs to get resized versions of itself!
327
- // Also, it may make sense to work on this in Pixel_Buffer for the moment.
328
-
329
-
330
-
331
-
332
- var that = this, callback, arr_image_item, buffer_image, type_name;
333
-
334
- console.log('get_resized_versions sig', sig);
335
-
336
- // if it's an array, we see what type of array it is.
337
- // it could be the buffer, then the type name
338
-
339
- // May be given an array of sizes to get.
340
- // Would do the processing on Pixel Buffers.
341
-
342
- // Possibly asyncronous function to get this as a Pixel Buffer?
343
- // Could we make a Pixel Buffer class operate directly on this class's Buffer? Should we?
344
-
345
- console.trace('');
346
- throw 'stop';
347
-
348
- if (sig == '[a,f]') {
349
- var sig0 = get_item_sig(a[0], 1);
350
-
351
- // Will be getting an array of sizes.
352
-
353
- console.log('sig0', sig0);
354
-
355
- if (sig0 == '[B,o]') {
356
- arr_image_item = a[0];
357
- buffer_image = arr_image_item[0];
358
- metadata = arr_image_item[1];
359
-
360
- type_name = metadata.type_name;
361
-
362
-
363
-
364
- // Maybe it would be better to use a better JPEG loading library.
365
- // node-webkit could be overkill.
366
-
367
- // Could even translate the existing JavaScript code to C++.
368
- // It may be more effective at loading JPEGs.
369
-
370
- //var Worker = require('webworker-threads').Worker;
371
- // var w = new Worker('worker.js'); // Standard API
372
-
373
- // You may also pass in a function:
374
-
375
- // Load the JPEG from a buffer, then generate resized versions from the RGBA pixel buffer.
376
-
377
- var jpeg = new jsgui_jpeg.JPEG({});
378
-
379
-
380
- jpeg.load_from_buffer(buffer_image, function(err, cb_jpeg_loaded) {
381
- if (err) {
382
- throw err;
383
- } else {
384
- console.log('jpeg loaded');
385
-
386
- // We then want to get an RGBA Pixel Buffer from it.
387
-
388
-
389
-
390
- throw 'stop';
391
- //postMessage('done');
392
- worker.close();
393
- }
394
- })
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
- //var pb = jsgui_jpeg.load_pixel_buffer_from_disk()
403
-
404
-
405
- // need to do the actual resizing too.
406
- // seems best to call on code in other module.
407
- // This resource system is nice, bur we really want to be using it to expose other functionality.
408
-
409
- // Could maybe use a jpeg library.
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
- }
420
-
421
- callback = a[1];
422
-
423
- }
424
-
425
-
426
- //throw 'stop';
427
-
428
-
429
- }),
430
-
431
- */
432
-
433
- /*
434
-
435
- 'get_document': function(key, callback) {
436
- // get the doc from the db.
437
- var that = this;
438
- var pool = that.meta.get('pool');
439
- var web_db = pool.get_resource('Web DB');
440
-
441
-
442
- // get document with type and metadata
443
-
444
- // get_document_full
445
- // would return an object with a few properties, including 'document'.
446
-
447
- // {document, type, metadata}
448
- // or value, type, metadata
449
-
450
-
451
-
452
-
453
- web_db.get_document_full(key, function(err, res_web_db_get_document) {
454
- if (err) {
455
- throw err;
456
- } else {
457
-
458
- // The web db could return more data.
459
- // That data could include the document type, and the metadata
460
-
461
-
462
- // get_document_with_metadata
463
- // would also include the mime type
464
-
465
-
466
-
467
- //console.log('res_web_db_get_document', res_web_db_get_document);
468
-
469
- // callback with the document value, no metadata.
470
-
471
- callback(null, res_web_db_get_document);
472
-
473
- }
474
- });
475
- },
476
-
477
- 'set_document': fp(function(a, sig) {
478
- // This needs to get metadata about the image document it is setting.
479
- // Will also make the document in various thumbnail sizes.
480
-
481
- console.log('Image Resource set_document sig', sig);
482
-
483
- // Also want to make and save resized versions of it.
484
- // Want to have a system of setting up different versions and automatic filters.
485
- // When one image changes, it could / should then sequentially make all the various derived images.
486
- // Don't want to implement that yet.
487
- // Just want a system where it makes resized versions of the images that are set as documents.
488
-
489
- // I think we do want some things in the database about the id of the original image
490
- // Possibly also transformation info?
491
- // Maybe that should be in the metadata system?
492
- // That would mean a less complicated database.
493
- // I think queries for metadata should probably be really fast anyway.
494
- // Get all images with an original image of ...
495
- // Want to easily and quickly be able to get the resized versions of images.
496
-
497
-
498
-
499
-
500
- // Also needs to set the non-resized as well.
501
-
502
- var key, value, type_name, metadata, callback, that = this;
503
-
504
- var pool = that.meta.get('pool');
505
- //console.log('pool', pool);
506
-
507
- var web_db = pool.get_resource('Web DB');
508
-
509
- //console.log('web_db', web_db);
510
-
511
- //throw 'stop';
512
-
513
-
514
- if (sig == '[s,B,s,f]') {
515
- // we work out the metadata and then use the web db resource's set_document.
516
-
517
- key = a[0]; value = a[1]; type_name = a[2]; callback = a[3];
518
-
519
- //console.log('callback', callback);
520
- //throw 'stop';
521
-
522
- // Best to get the image metadata.
523
- // get_metadata
524
- // value, type_name
525
-
526
- // and the format is in the metadata.
527
- // maybe have type_name as fairly simple format info.
528
- // .format could be more complicated.
529
- // type_name should be fine.
530
-
531
- if (type_name === 'jpeg') {
532
- var jpeg = new jsgui_jpeg.JPEG({});
533
-
534
-
535
- // I think load 24 bpp buffer by default when loading JPEGs.
536
-
537
- jpeg.load_from_buffer(value, function(err, cb_jpeg_loaded) {
538
- if (err) {
539
- throw err;
540
- } else {
541
- console.log('jpeg loaded');
542
-
543
- //pb = jpeg.get_rgb_enhanced_pixel_buffer();
544
-
545
- var pb = jpeg.get_rgba_enhanced_pixel_buffer();
546
-
547
- // then save a variety of smaller jpeg versions
548
-
549
-
550
-
551
-
552
- // Want to save a few resized / thumbnail versions.
553
- // Want the various sizes to be configurable - part of the DB?
554
-
555
-
556
-
557
-
558
- // get an rgba one.
559
-
560
-
561
- // I think by default will keep the ARs.
562
- // Same bits per pixel as well?
563
-
564
- // would be good to save that enhanced pixel buffer as a JPEG now.
565
-
566
- // It would work out from the file name that it's a JPEG.
567
-
568
-
569
- // pb.save('test.jpeg');
570
-
571
-
572
- // Can save the various resized versions to the database.
573
-
574
- // Could call a function to save the various resized objects.
575
-
576
- console.log('jpeg.size', jpeg.size);
577
-
578
- var md = {
579
- 'width': jpeg.size[0],
580
- 'height': jpeg.size[1]
581
- }
582
-
583
-
584
-
585
- // In some situations may want to load, encode before saving, maybe strip out dodgy metadata.
586
- web_db.set_document(key, value, type_name, md, function(err, uploaded_image_document_id) {
587
- if (err) {
588
- throw err;
589
- } else {
590
- console.log('cb save_square_sized_version set_document uploaded_image_document_id: ' + uploaded_image_document_id);
591
-
592
- // When describing transformed documents, we can reference them by key rather than integer id.
593
- // The different versions will still have different names, most likely given suffixes.
594
-
595
- // Then transform and save various versions of it.
596
-
597
-
598
- //throw 'stop';
599
- //callback2(null, res_saved);
600
-
601
-
602
- // need to look at the id of the item that was saved.
603
- // could possibly use its key to save the resized versions.
604
- // The resized versions will differ by name as well, but the transformations will be saved within the
605
- // database as well. That way it will be possible to logically view the original images, being served the
606
- // appropriate one for the device and required image size.
607
-
608
- var save_square_sized_version = function(square_size, callback2) {
609
- console.log('save_square_sized_version');
610
- //throw 'stop';
611
-
612
- var resized_128x128 = pb.get_resized([square_size, square_size]);
613
- var jpeg_128x128 = new jsgui_jpeg.JPEG({});
614
- jpeg_128x128.load_from_rgb_pixel_buffer(resized_128x128);
615
- var buffer_jpeg_128x128 = jpeg_128x128.save_to_buffer();
616
- var md = {
617
- 'width': resized_128x128.size[0],
618
- 'height': resized_128x128.size[1]
619
- }
620
- // Need to change the key, so insert the _128x128 before the extension.
621
-
622
- //var s_key = key.split('.');
623
- // need to replace the last full stop?
624
- var i = key.lastIndexOf('.');
625
- var key2 = key;
626
- if (i > -1) {
627
- key2 = key.substr(0, i) + '_' + square_size + 'x' + square_size + '.' + key.substr(i + 1);
628
- }
629
-
630
- console.log('key2', key2);
631
-
632
- web_db.set_document(key2, buffer_jpeg_128x128, type_name, md, function(err, res_saved) {
633
- if (err) {
634
- throw err;
635
- } else {
636
- console.log('cb save_square_sized_version set_document size: ' + square_size);
637
- //throw 'stop';
638
- callback2(null, res_saved);
639
-
640
-
641
-
642
-
643
-
644
-
645
-
646
- }
647
- });
648
-
649
- // Needs to set a document with a transformation reference.
650
-
651
- // Needs original document id.
652
-
653
- // set transformed document
654
- // orig id uploaded_image_document_id
655
- // transformation info
656
- // (include the transformation type)
657
- // possibly include the transformation parameters.
658
- // we know it's resize from the type, but the transformation params can include the size it
659
- // was transformed to. Could possibly use a normalized transformation parameters system.
660
-
661
- // .set_transformed_document(key2, transformed_buffer, type_name, metadata, transformation_type_name, transformation_params,
662
- // Need to create the document, while also creating the transformation record.
663
-
664
- // Or a document itself could have a transformation source?
665
- // Separate records would be more normalized.
666
- // I think just a bit more sensible.
667
-
668
- // A bit like the metadata record system.
669
- // Each transformation can have parameters which are similar in implementation to the metadata system.
670
-
671
-
672
- // Document transformations will be generally about reencoding a document.
673
-
674
- // Document_Transformations
675
- // id
676
- // source_document_id
677
- // target_document_id
678
- // transformation_verb_id
679
-
680
- // Document_Transformation_Parameters
681
- // could have different types, like integer parameters, string parameters
682
- // this system would help a lot with searching for documents of particular sizes.
683
- // Would be a bit time consuming to make, but would be useful for the end system where transformed
684
- // documents can better be searched for and retrieved very quickly.
685
-
686
- // dtrans_params
687
- // id, transformation id, key
688
-
689
- // Document Transformation Parameter (Record)s
690
- // id, transformation id, key
691
- // Document Transformation Integer Parameter (Record)s
692
- // These will be some of the most useful searchable and sortable parameters
693
-
694
- // Possible transformation: encode so that it's 50KB or less. Parameter could be an integer size.
695
-
696
- // Document Transformation Integer Parameters
697
- // id, transformation_param_id, value
698
-
699
- // Make the document transformation record + param records after the target document
700
- // has been put into the database.
701
-
702
- // Then save the resized one, as before,
703
-
704
- // Then save the transformation that connects the two saved images.
705
-
706
-
707
-
708
-
709
-
710
- };
711
-
712
- // Looks like it needs to save the original version and get the id first.
713
-
714
-
715
-
716
- save_square_sized_version(128, function(err, transformed_doc_id) {
717
- console.log('saved 128');
718
- //throw 'stop';
719
-
720
- if (err) {
721
- throw err;
722
- } else {
723
-
724
- console.log('transformed_doc_id', transformed_doc_id);
725
-
726
- web_db.ensure_transformation('resize', {'size': 128}, uploaded_image_document_id, transformed_doc_id, function(err, res_ensure_transformation) {
727
- if (err) {
728
- throw err;
729
- } else {
730
- console.log('res_ensure_transformation', res_ensure_transformation);
731
-
732
- callback2(null, res_saved);
733
-
734
-
735
- }
736
- })
737
-
738
-
739
-
740
-
741
- // need to save the resize transformation that connects them.
742
-
743
-
744
-
745
- //throw 'stop';
746
-
747
-
748
-
749
-
750
- }
751
-
752
- });
753
-
754
- }
755
- });
756
-
757
-
758
-
759
- // Should save the original file first, and then save the transformations based on it.
760
-
761
-
762
-
763
-
764
-
765
-
766
- // Could give an array of different sizes and filenames.
767
-
768
- // Would be good to get an array of the different sizes to save as.
769
- // Could also be useful to have fields for a description of the size
770
- // eg iPhone 5 portrait full screen
771
- // also iPhone 5 portrait portrait safari iOS 6 full window
772
- // could potentially be different in iOS 7.
773
-
774
- // Also different icon sizes.
775
- // For the moment, would be good to store it in a variety of different sizes.
776
- // A few thumbnail image sizes would be useful.
777
-
778
- // Don't have this configurable in the DB at the moment...
779
- // However the DB needs to know which images are related.
780
- // Could have image_versions, with size restrictions and filters applied.
781
-
782
- // Want to be able to handle icons in the DB.
783
-
784
- // Will be storing a binary document value with modified name and size metadata
785
- // For thumbnail images, may want 256x256 max.
786
- // Or 512x512, possibly then scaled down in the browser.
787
-
788
- // Then we may want 128x128 max or 64x64, scaled for viewing in a list or grid in the browser.
789
-
790
- // [64, 64], [128, 128], [256, 256], [512, 512], [800, 600], [1024, 768]
791
- // [64, 64], [128, 128], [256, 256], [512, 512], [1024, 1024]
792
- // second option seems better.
793
-
794
-
795
-
796
-
797
-
798
-
799
- // jpeg.save_resized()
800
-
801
- // Want to make and save a max 64x64 version.
802
- // It needs to be saved in the database as a different size.
803
-
804
- // put this in a function, so we can set a bunch of them quickly
805
-
806
- // And the save square sized version will deal with the db document transformation system.
807
- // Needs to mark the result images as being resized transformations based on an original.
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
- // Set a few resized versions....
817
- // 128x128
818
- // 258x256
819
- // 512x512
820
-
821
-
822
-
823
-
824
-
825
-
826
-
827
- // then save that JPEG to the database.
828
-
829
- // want to get the encoded JPEG buffer.
830
-
831
-
832
-
833
- // then create and save a JPEG with those max dimensions.
834
-
835
-
836
-
837
- // We then want to get an RGBA Pixel Buffer from it.
838
-
839
-
840
-
841
- //throw 'stop';
842
- //postMessage('done');
843
- //worker.close();
844
- }
845
- })
846
- }
847
-
848
-
849
- }
850
-
851
- }),
852
-
853
- */
854
-
855
- // can have both a directory path and a URL path.
856
- // don't want to necessarily serve them under /img/
857
-
858
-
859
-
860
-
861
- // want to be able to serve a path better.
862
- // still has bug here.
863
- 'serve_directory'(path) {
864
- // Serves that directory, as any files given in that directory can be served from /js
865
-
866
- //var served_directories = this.meta.get('served_directories');
867
- //console.log('served_directories ' + stringify(served_directories));
868
- //served_directories.push(path);
869
- this.served_directories.push({
870
- 'name': path
871
- });
872
- //console.log('served_directories ' + stringify(served_directories));
873
- //console.log('path ' + path);
874
-
875
- // We may be serving directories AS something.
876
-
877
- //throw 'stop';
878
-
879
- }
880
-
881
- // basically get requests, but can handle more than just get.
882
- 'process'(req, res) {
883
- //console.log('Site_Images processing');
884
- var remoteAddress = req.connection.remoteAddress;
885
-
886
- var custom_paths = this.custom_paths;
887
-
888
- var rurl = req.url;
889
- //var pool = this.pool;
890
- // should have a bunch of resources from the pool.
891
-
892
- //var pool_resources = pool.resources();
893
- //console.log('pool_resources ' + stringify(pool_resources));
894
-
895
- var url_parts = url.parse(req.url, true);
896
- //console.log('url_parts ' + stringify(url_parts));
897
- var splitPath = url_parts.path.substr(1).split('/');
898
- //console.log('resource site css splitPath ' + stringify(splitPath));
899
-
900
- if (rurl.substr(0, 1) == '/') rurl = rurl.substr(1);
901
- rurl = rurl.replace(/\./g, '☺');
902
- //console.log('rurl ' + rurl);
903
-
904
- var custom_response_entry = custom_paths[rurl];
905
-
906
-
907
- var that = this;
908
- //console.log('custom_response_entry ' + stringify(custom_response_entry));
909
-
910
- if (custom_response_entry) {
911
- var tcr = tof(custom_response_entry);
912
- //console.log('tcr ' + tcr);
913
-
914
- if (tcr == 'data_value') {
915
- val = custom_response_entry.value();
916
- //console.log('val ' + val);
917
-
918
- var tval = tof(val);
919
-
920
- if (tval == 'string') {
921
- // then it should be a local file path, serve it.
922
- serve_image_file_from_disk(val, res);
923
- }
924
- }
925
- //throw 'stop';
926
- } else {
927
- //console.log('splitPath', splitPath);
928
- if (splitPath.length > 0) {
929
-
930
- // Can check for /js folder.
931
- // There will be some fixed resources for the site.
932
- // They will be served by Resource objects.
933
- // There may be some overlap of resources, with there being some very fixed purpose
934
- // specific resources that could duplicate some features of the more general ones.
935
- // Eventually, some of the code from the more specific resources will be
936
- // replacable with code from the more general ones.
937
-
938
- // Site_JavaScript resource
939
- // Will serve JavaScript files needed for the site.
940
- // Could become more advanced at some points, serving particular builds.
941
-
942
-
943
- // img or images
944
-
945
- if (splitPath[0] == 'img' || splitPath[0] == 'images') {
946
- // Possibly could be something different?
947
- // May be best to look at the path within the image resource.
948
- //var sjs = pool.get_resource('Site JavaScript');
949
- //console.log('sjs ' + sjs);
950
-
951
- //throw 'stop';
952
-
953
- // determine the name of the file to serve, serve that file
954
- // Could use some more general kind of file server.
955
-
956
- // We may want to serve from disk.
957
- // I think this could work differently to an interface to the disk resource.
958
- // The image resource, like some others, could directly access the disk.
959
- // They may have their own bit of caching.
960
-
961
-
962
- //console.log('splitPath', splitPath);
963
-
964
- if (splitPath.length > 1) {
965
- // At this point, can look for the file on disk within the app directory.
966
- //console.log('rurl', rurl);
967
- //console.log('req.url', req.url);
968
- // replace /images/ with /img/
969
- var project_disk_path = req.url.replace('images/', 'img/');
970
- if (project_disk_path.substr(0, 1) == '/') project_disk_path = project_disk_path.substr(1);
971
-
972
- // try to load it from disk.
973
- // try to load it as a buffer
974
- fs2.load_file_as_buffer(project_disk_path, function (err, buffer) {
975
- if (err) {
976
- console.log('error loading ' + project_disk_path + ': ' + err);
977
-
978
-
979
- // Then try serving the file using the other methods, but will need to take care not to expect some resources to be there,
980
- // such as the web_data resource.
981
- // Want top have a very versitile web_data resource that uses a DB, but also to have the means to interact with the files on disk
982
- // in the project directory.
983
-
984
- res.writeHead(404, {
985
- "Content-Type": "text/plain"
986
- });
987
- res.write("404 Not Found\n");
988
- res.end();
989
-
990
- //throw 'stop';
991
-
992
-
993
- const old_fn = () => {
994
- if (splitPath.length == 2) {
995
-
996
-
997
- // Could check options to see if to look in the database, or the file system.
998
- // Perhaps could have a website document storage abstraction that will store in the file system or the
999
- // database.
1000
- var fileName = splitPath[1];
1001
-
1002
- // See if we can get the document with the key of the filename of the image.
1003
- // Perhaps it will be stored as a site image.
1004
-
1005
- that.get_document(fileName, function (err, res_get_document) {
1006
- if (err) {
1007
- throw err;
1008
- } else {
1009
- //console.log('res_get_document', res_get_document);
1010
- console.log('cb get document');
1011
-
1012
- // Now we have it,
1013
-
1014
- var doc_keys = Object.keys(res_get_document);
1015
- console.log('doc_keys', doc_keys);
1016
-
1017
- // Need to know more information, such as the type_name
1018
- // that extra info should probably get returned from the database.
1019
- }
1020
- });
1021
-
1022
- /*
1023
- //console.log('url_parts.path ' + url_parts.path);
1024
- var filePath = url_parts.path.substr(1);
1025
- //console.log('module.uri ' + module.uri);
1026
- var val2 = path.dirname(module.uri);
1027
- console.log('val2 ' + val2);
1028
- //throw '9) stop';
1029
- //var diskPath = val2 + '/../../images/' + fileName;
1030
- var diskPath = '../../ws/img/' + fileName;
1031
- // Also making use of custom paths...
1032
- // First check if such an image is in a specifically served directory.
1033
- var served_directories = this.meta.get('served_directories');
1034
- //console.log('served_directories ' + stringify(served_directories));
1035
- // see if the file exists in any of the served directories
1036
- // search for the file in the served directories.
1037
- // will be an asyncronous search, and use an array of function calls with call_multi.
1038
- var fns = [];
1039
- var found_path;
1040
- each(served_directories, function(served_directory) {
1041
- //console.log('served_directory', served_directory);
1042
- var dir_val = served_directory.value();
1043
- //console.log('dir_val', dir_val);
1044
- var dir_name = dir_val.name;
1045
- //console.log('dir_name', dir_name);
1046
- var search_path = dir_name + '/' + fileName;
1047
- //console.log('search_path', search_path);
1048
- fns.push(function(callback) {
1049
- // check that directory
1050
- fs.exists(search_path, function(exists) {
1051
- //console.log('exists', exists);
1052
- if (!found_path && exists) {
1053
- found_path = search_path;
1054
- }
1055
- callback(null, exists);
1056
- })
1057
- })
1058
- });
1059
- call_multi(fns, function(err, res2) {
1060
- if (err) {
1061
- throw err;
1062
- } else {
1063
- //console.log('found_path', found_path);
1064
- if (found_path) {
1065
- diskPath = found_path;
1066
- serve_image_file_from_disk(diskPath, res);
1067
- }
1068
- }
1069
- });
1070
- //throw 'stop';
1071
- */
1072
-
1073
- /*
1074
- fs2.load_file_as_string(diskPath, function (err, data) {
1075
- if (err) {
1076
- throw err;
1077
- } else {
1078
- //var servableJs = updateReferencesForServing(data);
1079
- res.writeHead(200, {'Content-Type': 'text/css'});
1080
- res.end(data);
1081
- }
1082
- });
1083
- */
1084
- } else {
1085
- if (splitPath.length > 2) {
1086
- // need to put the rest of it together...
1087
- var fileName = splitPath.slice(1, splitPath.length).join('/');
1088
- console.log('fileName', fileName);
1089
- var filePath = url_parts.path.substr(1);
1090
- //console.log('module.uri ' + module.uri);
1091
- var val2 = path.dirname(module.uri);
1092
- console.log('val2 ' + val2);
1093
- //throw '9) stop';
1094
- //var diskPath = val2 + '/../../images/' + fileName;
1095
- var diskPath = '../../ws/img/' + fileName;
1096
- // Do the search in the various served directories for the file.
1097
-
1098
- var served_directories = this.served_directories;
1099
- //console.log('served_directories ' + stringify(served_directories));
1100
- // see if the file exists in any of the served directories
1101
- // search for the file in the served directories.
1102
- // will be an asyncronous search, and use an array of function calls with call_multi.
1103
-
1104
- var fns = [];
1105
- var found_path;
1106
- each(served_directories, function (served_directory) {
1107
- //console.log('served_directory', served_directory);
1108
- var dir_val = served_directory.value();
1109
- //console.log('dir_val', dir_val);
1110
- var dir_name = dir_val.name;
1111
- //console.log('dir_name', dir_name);
1112
-
1113
- var search_path = dir_name + '/' + fileName;
1114
- //console.log('search_path', search_path);
1115
- fns.push(function (callback) {
1116
- // check that directory
1117
-
1118
- fs.exists(search_path, function (exists) {
1119
- //console.log('exists', exists);
1120
-
1121
- if (!found_path && exists) {
1122
- found_path = search_path;
1123
- }
1124
- callback(null, exists);
1125
- })
1126
- })
1127
- });
1128
-
1129
- call_multi(fns, function (err, res2) {
1130
- if (err) {
1131
- throw err;
1132
- } else {
1133
- console.log('found_path', found_path);
1134
- if (found_path) {
1135
- diskPath = found_path;
1136
- //serve_image_file_from_disk(diskPath, res);
1137
- }
1138
- serve_image_file_from_disk(diskPath, res);
1139
- }
1140
- });
1141
- // /js/core/jsgui-lang-enh
1142
- //console.log('!*!*!*! url_parts.path ' + url_parts.path);
1143
- /*
1144
- if (splitPath[1] == 'core') {
1145
- var fileName = splitPath[2];
1146
- var val2 = path.dirname(module.uri);
1147
- //console.log('val2 ' + val2);
1148
- var diskPath = val2 + '/../core/' + fileName;
1149
- fs2.load_file_as_string(diskPath, function (err, data) {
1150
- if (err) {
1151
- throw err;
1152
- } else {
1153
- //var servableJs = updateReferencesForServing(data);
1154
- res.writeHead(200, {'Content-Type': 'text/css'});
1155
- res.end(data);
1156
- }
1157
- });
1158
- }
1159
- */
1160
- }
1161
- }
1162
- }
1163
- } else {
1164
- console.log('loaded file, need to serve it');
1165
- // need to set the mime type correctly.
1166
- // We can get this from the file name for the moment.
1167
- // serve_image_file_from_buffer
1168
- //serve_image_file_from_disk(diskPath, res);
1169
- console.log('buffer', buffer);
1170
- console.log('project_disk_path', project_disk_path);
1171
- serve_image_file_from_buffer(buffer, project_disk_path, res);
1172
- }
1173
- })
1174
- }
1175
- }
1176
- }
1177
- }
1178
- }
1179
- }
1180
-
1181
-
1182
- //return Site_Images;
1183
-
1184
-
1185
- //});
1
+ /*
2
+ if (typeof define !== 'function') {
3
+ var define = require('amdefine')(module);
4
+ }
5
+
6
+ define(['module', 'path', 'fs', 'url', '../../web/jsgui-html', 'os', 'http', 'url', './resource',
7
+ '../../web/jsgui-je-suis-xml', 'cookies', '../../fs/jsgui-node-fs2-core',
8
+ //"jpeg-js",
9
+ '../../image/node/jsgui-node-jpeg',
10
+ '../../image/node/jsgui-node-png',
11
+ 'webworker-threads'],
12
+
13
+ function(module, path, fs, url, jsgui, os, http, libUrl,
14
+ Resource, JeSuisXML, Cookies, fs2,
15
+ jsgui_jpeg,
16
+ jsgui_png,
17
+ Worker) {
18
+ */
19
+
20
+
21
+ // 24/07/2019 - Looks like this needs more work.
22
+ // Want to provide simple and powerful API.
23
+
24
+ // Specifically being able to deal with icons and a directory of icons.
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ var path = require('path'),
33
+ fs = require('fs'),
34
+ url = require('url'),
35
+ jsgui = require('jsgui3-html'),
36
+ os = require('os'),
37
+ http = require('http'),
38
+ libUrl = require('url'),
39
+ Resource = jsgui.Resource;
40
+
41
+ fs2 = require('../fs2');
42
+
43
+ // Then could this connect to a cms db?
44
+ // Or a wider source of images?
45
+ // Mapping the ws image requests to acquiring the image data.
46
+ // Won't necessarily be on disk. Could call to another resource, such as network / file / files on network.
47
+ // Could map over / use another resource.
48
+
49
+ /*
50
+
51
+ jsgui_jpeg = require('../../image/node/jsgui-node-jpeg'),
52
+ jsgui_png = require('../../image/node/jsgui-node-png');
53
+
54
+
55
+ */
56
+ //Worker = require('webworker-threads');
57
+
58
+ var stringify = jsgui.stringify,
59
+ each = jsgui.eac,
60
+ arrayify = jsgui.arrayify,
61
+ tof = jsgui.tof;
62
+ var call_multi = jsgui.call_multi;
63
+ var filter_map_by_regex = jsgui.filter_map_by_regex;
64
+ var Class = jsgui.Class,
65
+ Data_Object = jsgui.Data_Object,
66
+ Enhanced_Data_Object = jsgui.Enhanced_Data_Object;
67
+ var fp = jsgui.fp,
68
+ is_defined = jsgui.is_defined;
69
+ var get_item_sig = jsgui.get_item_sig;
70
+ var Collection = jsgui.Collection;
71
+
72
+ // This resource may have quite a lot of functionality put in to deal with
73
+ // seriving images in an optimized way.
74
+ // Want this so it also serves the developer in that images can be put in place
75
+ // and modified easily in an unoptimized way. Then they get put in place in an
76
+ // optimized way on request or automatically. Want to incorporate sprite sheet generation
77
+ // here. This should handle requests for individual images, but it's also possible sprites
78
+ // could be requested. If that's the case, maybe it should pass it onto a sprite resource.
79
+ // It would be really good to have practically instant sprite generation, using C / C++
80
+ // and maybe OpenCL.
81
+ // It could be requests to a sprite resource that returns a predefined selection of
82
+ // assets.
83
+ // The image resource may also be called upon to return rescaled versions.
84
+ // That's something that OpenCL would also be very fast at.
85
+ // The image / spritesheet resources may be connected to other database resources that provide
86
+ // caching and indexing of images.
87
+ // These would most likely be abstractions over data resources.
88
+
89
+ // Want to make an image interface to a flexible db interface.
90
+ // Serving and caching optimized images would be cool.
91
+
92
+ // Rather than relying on storing image versions in a DB (which would be cool, esp for distributed)
93
+ // we can store image versions + spritesheets on the local disk.
94
+ // Cache them in RAM as well.
95
+ // Storing them in GPU RAM would be very cool, especially if from there we can get versions with
96
+ // different operations done, or the output of operations.
97
+
98
+
99
+ // May need to change around a fair few references to make it workable.
100
+ // May need some more complicated logic to change it to the path for service.
101
+
102
+
103
+
104
+ // This is going to be extended so that it works with the Web_DB_Resource system.
105
+
106
+ // Will have further handling on images, hopefully just deal with the DB side of things as file storage.
107
+ // Will keep image processing algorithms (and probably calls) out of the Web_DB_Postgres module, but use that interface
108
+ // to interact with images.
109
+
110
+ // This module should also be comfortable dealing with images from the file system.
111
+
112
+ // Also want to be able to quickly get thumbnails of images.
113
+
114
+ // Will refer to images by a 'key', and also specify a size to get / display the image at
115
+ // The point will be to make it easy to program the appearance of the image, not having to keep track of the URL, having the image
116
+ // within a convenient admin system.
117
+
118
+ // Serving a thumbnail, based on the image key, makes the most sense.
119
+
120
+ // Want to be able to get the URL for an image from the key.
121
+ // Will also be able to get thumbnail URLs.
122
+
123
+ // I think this Resource will also have more specialised functionality, possibly handlers too, that will be used by other modules.
124
+
125
+ // Add an image to the database, along with it's metadata, and thumbnail versions.
126
+ // Thumbnail versions under key _400x300
127
+ // I think x will be an OK separator here.
128
+ // That size will refer to their maximum dimensions.
129
+
130
+
131
+
132
+
133
+ // need to see what type of image it is.
134
+ var mime_types = {
135
+ 'jpg': 'image/jpeg',
136
+ 'jpeg': 'image/jpeg',
137
+ 'gif': 'image/gif',
138
+ 'png': 'image/png',
139
+ 'svg': 'image/svg+xml',
140
+ 'otf': 'application/font-sfnt',
141
+ 'ttf': 'application/font-sfnt'
142
+ }
143
+
144
+ var serve_image_file_from_buffer = function (buffer, filename, response) {
145
+ console.log('filename', filename);
146
+ var extname = path.extname(filename);
147
+ console.log('extname ' + extname);
148
+
149
+ var extension = extname.substr(1);
150
+ console.log('extension ' + extension);
151
+
152
+ response.writeHead(200, {
153
+ 'Content-Type': mime_types[extension]
154
+ });
155
+ response.end(buffer, 'binary');
156
+ }
157
+
158
+
159
+ var serve_image_file_from_disk = function (filePath, response) {
160
+ var extname = path.extname(filePath);
161
+ console.log('extname ' + extname);
162
+ var extension = extname.substr(1);
163
+ console.log('extension ' + extension);
164
+
165
+ // then return the right MIME type for that extension.
166
+
167
+ // No, don't load the image file as a string.
168
+
169
+ // fs loadfile
170
+ // async, then serve it with the correct mime type, write to the response buffer.
171
+
172
+ // can this be streamed to the response buffer?
173
+
174
+ fs.readFile(filePath, function (err, data) {
175
+ if (err) {
176
+ throw err;
177
+ } else {
178
+ response.writeHead(200, {
179
+ 'Content-Type': mime_types[extension]
180
+ });
181
+ response.end(data, 'binary');
182
+ }
183
+ });
184
+
185
+
186
+ //fs2.load_file_as_string(filePath, function (err, data) {
187
+ // if (err) {
188
+ // throw err;
189
+ // } else {
190
+ // //var servableJs = updateReferencesForServing(data);
191
+ // response.writeHead(200, {'Content-Type': mime_types[extension]});
192
+ // response.end(data);
193
+ // }
194
+ //});
195
+ }
196
+
197
+
198
+ class Site_Images extends Resource {
199
+
200
+
201
+ constructor(spec) {
202
+ super(spec);
203
+
204
+ //this.meta.set('custom_paths', new Data_Object({}));
205
+
206
+ //this.custom_paths = new Data_Object({});
207
+ this.custom_paths = {};
208
+
209
+
210
+ // Those are custom file paths.
211
+
212
+ // could have a collection of directories, indexed by name, that get served.
213
+
214
+ // Index the collection by string value?
215
+ //this.meta.set('served_directories', new Collection({'index_by': 'name'}));
216
+ this.served_directories = new Collection({
217
+ 'index_by': 'name'
218
+ });
219
+
220
+ }
221
+ 'start'(callback) {
222
+ callback(null, true);
223
+ }
224
+ 'get_image_url'(image_key) {
225
+
226
+ }
227
+ 'get_icon_url'(icon_key) {
228
+ // May have different size icons
229
+ // For the moment will keep this simple.
230
+
231
+ return '/img/icons/' + icon_key + '.png';
232
+
233
+
234
+ }
235
+
236
+
237
+ /*
238
+ 'get_metadata': fp(function(a, sig) {
239
+ console.log('get_metadata sig', sig);
240
+
241
+ var value, type_name, callback;
242
+ if (sig == '[B,s,f]') {
243
+ value = a[0]; type_name = a[1]; callback = a[2];
244
+
245
+ if (type_name === 'jpeg') {
246
+
247
+ // do this in a web worker?
248
+ //console.log('pre run web worker')
249
+
250
+
251
+ //var worker = new Worker.Worker(function() {
252
+ //console.log('running web worker')
253
+ ////postMessage("I'm working before postMessage('ali').");
254
+ ////this.onmessage = function(event) {
255
+ //// But does the worker have access to jpeg_js?
256
+ //console.log('pre decode');
257
+ //var decoded = jpeg_js.decode(value);
258
+ //console.log('post decode');
259
+ //var width = decoded.width;
260
+ //var height = decoded.height;
261
+ //var res = {
262
+ //'width': width,
263
+ //'height': height,
264
+ //'type_name': type_name
265
+ //}
266
+ //callback(null, res);
267
+ //postMessage(res);
268
+ //worker.close();
269
+ //});
270
+ //worker.onmessage = function(event) {
271
+ //console.log("Worker said : " + event.data);
272
+ //};
273
+
274
+
275
+
276
+ // It would be nice to improve the speed of the JPEG_JS module.
277
+
278
+ var jpeg = new jsgui_jpeg.JPEG({});
279
+
280
+ // load_size_from_buffer
281
+
282
+
283
+
284
+
285
+ jpeg.load_size_from_buffer(value, function(err, size) {
286
+ if (err) {
287
+ // But if there was an error loading the JPEG, it needs to raise an error.
288
+ // I'm now going to use
289
+
290
+
291
+ throw err;
292
+
293
+ } else {
294
+
295
+
296
+ //console.log('jpeg loaded');
297
+
298
+ //console.log('size', size);
299
+
300
+ //throw 'stop';
301
+
302
+ callback(null, {
303
+ 'size': size
304
+ });
305
+
306
+
307
+
308
+ }
309
+ })
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+ }
318
+ }
319
+ }),
320
+ */
321
+
322
+ /*
323
+
324
+ '__get_resized_versions': fp(function(a, sig) {
325
+
326
+ // No, this needs to get resized versions of itself!
327
+ // Also, it may make sense to work on this in Pixel_Buffer for the moment.
328
+
329
+
330
+
331
+
332
+ var that = this, callback, arr_image_item, buffer_image, type_name;
333
+
334
+ console.log('get_resized_versions sig', sig);
335
+
336
+ // if it's an array, we see what type of array it is.
337
+ // it could be the buffer, then the type name
338
+
339
+ // May be given an array of sizes to get.
340
+ // Would do the processing on Pixel Buffers.
341
+
342
+ // Possibly asyncronous function to get this as a Pixel Buffer?
343
+ // Could we make a Pixel Buffer class operate directly on this class's Buffer? Should we?
344
+
345
+ console.trace('');
346
+ throw 'stop';
347
+
348
+ if (sig == '[a,f]') {
349
+ var sig0 = get_item_sig(a[0], 1);
350
+
351
+ // Will be getting an array of sizes.
352
+
353
+ console.log('sig0', sig0);
354
+
355
+ if (sig0 == '[B,o]') {
356
+ arr_image_item = a[0];
357
+ buffer_image = arr_image_item[0];
358
+ metadata = arr_image_item[1];
359
+
360
+ type_name = metadata.type_name;
361
+
362
+
363
+
364
+ // Maybe it would be better to use a better JPEG loading library.
365
+ // node-webkit could be overkill.
366
+
367
+ // Could even translate the existing JavaScript code to C++.
368
+ // It may be more effective at loading JPEGs.
369
+
370
+ //var Worker = require('webworker-threads').Worker;
371
+ // var w = new Worker('worker.js'); // Standard API
372
+
373
+ // You may also pass in a function:
374
+
375
+ // Load the JPEG from a buffer, then generate resized versions from the RGBA pixel buffer.
376
+
377
+ var jpeg = new jsgui_jpeg.JPEG({});
378
+
379
+
380
+ jpeg.load_from_buffer(buffer_image, function(err, cb_jpeg_loaded) {
381
+ if (err) {
382
+ throw err;
383
+ } else {
384
+ console.log('jpeg loaded');
385
+
386
+ // We then want to get an RGBA Pixel Buffer from it.
387
+
388
+
389
+
390
+ throw 'stop';
391
+ //postMessage('done');
392
+ worker.close();
393
+ }
394
+ })
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+ //var pb = jsgui_jpeg.load_pixel_buffer_from_disk()
403
+
404
+
405
+ // need to do the actual resizing too.
406
+ // seems best to call on code in other module.
407
+ // This resource system is nice, bur we really want to be using it to expose other functionality.
408
+
409
+ // Could maybe use a jpeg library.
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+ }
420
+
421
+ callback = a[1];
422
+
423
+ }
424
+
425
+
426
+ //throw 'stop';
427
+
428
+
429
+ }),
430
+
431
+ */
432
+
433
+ /*
434
+
435
+ 'get_document': function(key, callback) {
436
+ // get the doc from the db.
437
+ var that = this;
438
+ var pool = that.meta.get('pool');
439
+ var web_db = pool.get_resource('Web DB');
440
+
441
+
442
+ // get document with type and metadata
443
+
444
+ // get_document_full
445
+ // would return an object with a few properties, including 'document'.
446
+
447
+ // {document, type, metadata}
448
+ // or value, type, metadata
449
+
450
+
451
+
452
+
453
+ web_db.get_document_full(key, function(err, res_web_db_get_document) {
454
+ if (err) {
455
+ throw err;
456
+ } else {
457
+
458
+ // The web db could return more data.
459
+ // That data could include the document type, and the metadata
460
+
461
+
462
+ // get_document_with_metadata
463
+ // would also include the mime type
464
+
465
+
466
+
467
+ //console.log('res_web_db_get_document', res_web_db_get_document);
468
+
469
+ // callback with the document value, no metadata.
470
+
471
+ callback(null, res_web_db_get_document);
472
+
473
+ }
474
+ });
475
+ },
476
+
477
+ 'set_document': fp(function(a, sig) {
478
+ // This needs to get metadata about the image document it is setting.
479
+ // Will also make the document in various thumbnail sizes.
480
+
481
+ console.log('Image Resource set_document sig', sig);
482
+
483
+ // Also want to make and save resized versions of it.
484
+ // Want to have a system of setting up different versions and automatic filters.
485
+ // When one image changes, it could / should then sequentially make all the various derived images.
486
+ // Don't want to implement that yet.
487
+ // Just want a system where it makes resized versions of the images that are set as documents.
488
+
489
+ // I think we do want some things in the database about the id of the original image
490
+ // Possibly also transformation info?
491
+ // Maybe that should be in the metadata system?
492
+ // That would mean a less complicated database.
493
+ // I think queries for metadata should probably be really fast anyway.
494
+ // Get all images with an original image of ...
495
+ // Want to easily and quickly be able to get the resized versions of images.
496
+
497
+
498
+
499
+
500
+ // Also needs to set the non-resized as well.
501
+
502
+ var key, value, type_name, metadata, callback, that = this;
503
+
504
+ var pool = that.meta.get('pool');
505
+ //console.log('pool', pool);
506
+
507
+ var web_db = pool.get_resource('Web DB');
508
+
509
+ //console.log('web_db', web_db);
510
+
511
+ //throw 'stop';
512
+
513
+
514
+ if (sig == '[s,B,s,f]') {
515
+ // we work out the metadata and then use the web db resource's set_document.
516
+
517
+ key = a[0]; value = a[1]; type_name = a[2]; callback = a[3];
518
+
519
+ //console.log('callback', callback);
520
+ //throw 'stop';
521
+
522
+ // Best to get the image metadata.
523
+ // get_metadata
524
+ // value, type_name
525
+
526
+ // and the format is in the metadata.
527
+ // maybe have type_name as fairly simple format info.
528
+ // .format could be more complicated.
529
+ // type_name should be fine.
530
+
531
+ if (type_name === 'jpeg') {
532
+ var jpeg = new jsgui_jpeg.JPEG({});
533
+
534
+
535
+ // I think load 24 bpp buffer by default when loading JPEGs.
536
+
537
+ jpeg.load_from_buffer(value, function(err, cb_jpeg_loaded) {
538
+ if (err) {
539
+ throw err;
540
+ } else {
541
+ console.log('jpeg loaded');
542
+
543
+ //pb = jpeg.get_rgb_enhanced_pixel_buffer();
544
+
545
+ var pb = jpeg.get_rgba_enhanced_pixel_buffer();
546
+
547
+ // then save a variety of smaller jpeg versions
548
+
549
+
550
+
551
+
552
+ // Want to save a few resized / thumbnail versions.
553
+ // Want the various sizes to be configurable - part of the DB?
554
+
555
+
556
+
557
+
558
+ // get an rgba one.
559
+
560
+
561
+ // I think by default will keep the ARs.
562
+ // Same bits per pixel as well?
563
+
564
+ // would be good to save that enhanced pixel buffer as a JPEG now.
565
+
566
+ // It would work out from the file name that it's a JPEG.
567
+
568
+
569
+ // pb.save('test.jpeg');
570
+
571
+
572
+ // Can save the various resized versions to the database.
573
+
574
+ // Could call a function to save the various resized objects.
575
+
576
+ console.log('jpeg.size', jpeg.size);
577
+
578
+ var md = {
579
+ 'width': jpeg.size[0],
580
+ 'height': jpeg.size[1]
581
+ }
582
+
583
+
584
+
585
+ // In some situations may want to load, encode before saving, maybe strip out dodgy metadata.
586
+ web_db.set_document(key, value, type_name, md, function(err, uploaded_image_document_id) {
587
+ if (err) {
588
+ throw err;
589
+ } else {
590
+ console.log('cb save_square_sized_version set_document uploaded_image_document_id: ' + uploaded_image_document_id);
591
+
592
+ // When describing transformed documents, we can reference them by key rather than integer id.
593
+ // The different versions will still have different names, most likely given suffixes.
594
+
595
+ // Then transform and save various versions of it.
596
+
597
+
598
+ //throw 'stop';
599
+ //callback2(null, res_saved);
600
+
601
+
602
+ // need to look at the id of the item that was saved.
603
+ // could possibly use its key to save the resized versions.
604
+ // The resized versions will differ by name as well, but the transformations will be saved within the
605
+ // database as well. That way it will be possible to logically view the original images, being served the
606
+ // appropriate one for the device and required image size.
607
+
608
+ var save_square_sized_version = function(square_size, callback2) {
609
+ console.log('save_square_sized_version');
610
+ //throw 'stop';
611
+
612
+ var resized_128x128 = pb.get_resized([square_size, square_size]);
613
+ var jpeg_128x128 = new jsgui_jpeg.JPEG({});
614
+ jpeg_128x128.load_from_rgb_pixel_buffer(resized_128x128);
615
+ var buffer_jpeg_128x128 = jpeg_128x128.save_to_buffer();
616
+ var md = {
617
+ 'width': resized_128x128.size[0],
618
+ 'height': resized_128x128.size[1]
619
+ }
620
+ // Need to change the key, so insert the _128x128 before the extension.
621
+
622
+ //var s_key = key.split('.');
623
+ // need to replace the last full stop?
624
+ var i = key.lastIndexOf('.');
625
+ var key2 = key;
626
+ if (i > -1) {
627
+ key2 = key.substr(0, i) + '_' + square_size + 'x' + square_size + '.' + key.substr(i + 1);
628
+ }
629
+
630
+ console.log('key2', key2);
631
+
632
+ web_db.set_document(key2, buffer_jpeg_128x128, type_name, md, function(err, res_saved) {
633
+ if (err) {
634
+ throw err;
635
+ } else {
636
+ console.log('cb save_square_sized_version set_document size: ' + square_size);
637
+ //throw 'stop';
638
+ callback2(null, res_saved);
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+ }
647
+ });
648
+
649
+ // Needs to set a document with a transformation reference.
650
+
651
+ // Needs original document id.
652
+
653
+ // set transformed document
654
+ // orig id uploaded_image_document_id
655
+ // transformation info
656
+ // (include the transformation type)
657
+ // possibly include the transformation parameters.
658
+ // we know it's resize from the type, but the transformation params can include the size it
659
+ // was transformed to. Could possibly use a normalized transformation parameters system.
660
+
661
+ // .set_transformed_document(key2, transformed_buffer, type_name, metadata, transformation_type_name, transformation_params,
662
+ // Need to create the document, while also creating the transformation record.
663
+
664
+ // Or a document itself could have a transformation source?
665
+ // Separate records would be more normalized.
666
+ // I think just a bit more sensible.
667
+
668
+ // A bit like the metadata record system.
669
+ // Each transformation can have parameters which are similar in implementation to the metadata system.
670
+
671
+
672
+ // Document transformations will be generally about reencoding a document.
673
+
674
+ // Document_Transformations
675
+ // id
676
+ // source_document_id
677
+ // target_document_id
678
+ // transformation_verb_id
679
+
680
+ // Document_Transformation_Parameters
681
+ // could have different types, like integer parameters, string parameters
682
+ // this system would help a lot with searching for documents of particular sizes.
683
+ // Would be a bit time consuming to make, but would be useful for the end system where transformed
684
+ // documents can better be searched for and retrieved very quickly.
685
+
686
+ // dtrans_params
687
+ // id, transformation id, key
688
+
689
+ // Document Transformation Parameter (Record)s
690
+ // id, transformation id, key
691
+ // Document Transformation Integer Parameter (Record)s
692
+ // These will be some of the most useful searchable and sortable parameters
693
+
694
+ // Possible transformation: encode so that it's 50KB or less. Parameter could be an integer size.
695
+
696
+ // Document Transformation Integer Parameters
697
+ // id, transformation_param_id, value
698
+
699
+ // Make the document transformation record + param records after the target document
700
+ // has been put into the database.
701
+
702
+ // Then save the resized one, as before,
703
+
704
+ // Then save the transformation that connects the two saved images.
705
+
706
+
707
+
708
+
709
+
710
+ };
711
+
712
+ // Looks like it needs to save the original version and get the id first.
713
+
714
+
715
+
716
+ save_square_sized_version(128, function(err, transformed_doc_id) {
717
+ console.log('saved 128');
718
+ //throw 'stop';
719
+
720
+ if (err) {
721
+ throw err;
722
+ } else {
723
+
724
+ console.log('transformed_doc_id', transformed_doc_id);
725
+
726
+ web_db.ensure_transformation('resize', {'size': 128}, uploaded_image_document_id, transformed_doc_id, function(err, res_ensure_transformation) {
727
+ if (err) {
728
+ throw err;
729
+ } else {
730
+ console.log('res_ensure_transformation', res_ensure_transformation);
731
+
732
+ callback2(null, res_saved);
733
+
734
+
735
+ }
736
+ })
737
+
738
+
739
+
740
+
741
+ // need to save the resize transformation that connects them.
742
+
743
+
744
+
745
+ //throw 'stop';
746
+
747
+
748
+
749
+
750
+ }
751
+
752
+ });
753
+
754
+ }
755
+ });
756
+
757
+
758
+
759
+ // Should save the original file first, and then save the transformations based on it.
760
+
761
+
762
+
763
+
764
+
765
+
766
+ // Could give an array of different sizes and filenames.
767
+
768
+ // Would be good to get an array of the different sizes to save as.
769
+ // Could also be useful to have fields for a description of the size
770
+ // eg iPhone 5 portrait full screen
771
+ // also iPhone 5 portrait portrait safari iOS 6 full window
772
+ // could potentially be different in iOS 7.
773
+
774
+ // Also different icon sizes.
775
+ // For the moment, would be good to store it in a variety of different sizes.
776
+ // A few thumbnail image sizes would be useful.
777
+
778
+ // Don't have this configurable in the DB at the moment...
779
+ // However the DB needs to know which images are related.
780
+ // Could have image_versions, with size restrictions and filters applied.
781
+
782
+ // Want to be able to handle icons in the DB.
783
+
784
+ // Will be storing a binary document value with modified name and size metadata
785
+ // For thumbnail images, may want 256x256 max.
786
+ // Or 512x512, possibly then scaled down in the browser.
787
+
788
+ // Then we may want 128x128 max or 64x64, scaled for viewing in a list or grid in the browser.
789
+
790
+ // [64, 64], [128, 128], [256, 256], [512, 512], [800, 600], [1024, 768]
791
+ // [64, 64], [128, 128], [256, 256], [512, 512], [1024, 1024]
792
+ // second option seems better.
793
+
794
+
795
+
796
+
797
+
798
+
799
+ // jpeg.save_resized()
800
+
801
+ // Want to make and save a max 64x64 version.
802
+ // It needs to be saved in the database as a different size.
803
+
804
+ // put this in a function, so we can set a bunch of them quickly
805
+
806
+ // And the save square sized version will deal with the db document transformation system.
807
+ // Needs to mark the result images as being resized transformations based on an original.
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+ // Set a few resized versions....
817
+ // 128x128
818
+ // 258x256
819
+ // 512x512
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+ // then save that JPEG to the database.
828
+
829
+ // want to get the encoded JPEG buffer.
830
+
831
+
832
+
833
+ // then create and save a JPEG with those max dimensions.
834
+
835
+
836
+
837
+ // We then want to get an RGBA Pixel Buffer from it.
838
+
839
+
840
+
841
+ //throw 'stop';
842
+ //postMessage('done');
843
+ //worker.close();
844
+ }
845
+ })
846
+ }
847
+
848
+
849
+ }
850
+
851
+ }),
852
+
853
+ */
854
+
855
+ // can have both a directory path and a URL path.
856
+ // don't want to necessarily serve them under /img/
857
+
858
+
859
+
860
+
861
+ // want to be able to serve a path better.
862
+ // still has bug here.
863
+ 'serve_directory'(path) {
864
+ // Serves that directory, as any files given in that directory can be served from /js
865
+
866
+ //var served_directories = this.meta.get('served_directories');
867
+ //console.log('served_directories ' + stringify(served_directories));
868
+ //served_directories.push(path);
869
+ this.served_directories.push({
870
+ 'name': path
871
+ });
872
+ //console.log('served_directories ' + stringify(served_directories));
873
+ //console.log('path ' + path);
874
+
875
+ // We may be serving directories AS something.
876
+
877
+ //throw 'stop';
878
+
879
+ }
880
+
881
+ // basically get requests, but can handle more than just get.
882
+ 'process'(req, res) {
883
+ //console.log('Site_Images processing');
884
+ var remoteAddress = req.connection.remoteAddress;
885
+
886
+ var custom_paths = this.custom_paths;
887
+
888
+ var rurl = req.url;
889
+ //var pool = this.pool;
890
+ // should have a bunch of resources from the pool.
891
+
892
+ //var pool_resources = pool.resources();
893
+ //console.log('pool_resources ' + stringify(pool_resources));
894
+
895
+ var url_parts = url.parse(req.url, true);
896
+ //console.log('url_parts ' + stringify(url_parts));
897
+ var splitPath = url_parts.path.substr(1).split('/');
898
+ //console.log('resource site css splitPath ' + stringify(splitPath));
899
+
900
+ if (rurl.substr(0, 1) == '/') rurl = rurl.substr(1);
901
+ rurl = rurl.replace(/\./g, '☺');
902
+ //console.log('rurl ' + rurl);
903
+
904
+ var custom_response_entry = custom_paths[rurl];
905
+
906
+
907
+ var that = this;
908
+ //console.log('custom_response_entry ' + stringify(custom_response_entry));
909
+
910
+ if (custom_response_entry) {
911
+ var tcr = tof(custom_response_entry);
912
+ //console.log('tcr ' + tcr);
913
+
914
+ if (tcr == 'data_value') {
915
+ val = custom_response_entry.value();
916
+ //console.log('val ' + val);
917
+
918
+ var tval = tof(val);
919
+
920
+ if (tval == 'string') {
921
+ // then it should be a local file path, serve it.
922
+ serve_image_file_from_disk(val, res);
923
+ }
924
+ }
925
+ //throw 'stop';
926
+ } else {
927
+ //console.log('splitPath', splitPath);
928
+ if (splitPath.length > 0) {
929
+
930
+ // Can check for /js folder.
931
+ // There will be some fixed resources for the site.
932
+ // They will be served by Resource objects.
933
+ // There may be some overlap of resources, with there being some very fixed purpose
934
+ // specific resources that could duplicate some features of the more general ones.
935
+ // Eventually, some of the code from the more specific resources will be
936
+ // replacable with code from the more general ones.
937
+
938
+ // Site_JavaScript resource
939
+ // Will serve JavaScript files needed for the site.
940
+ // Could become more advanced at some points, serving particular builds.
941
+
942
+
943
+ // img or images
944
+
945
+ if (splitPath[0] == 'img' || splitPath[0] == 'images') {
946
+ // Possibly could be something different?
947
+ // May be best to look at the path within the image resource.
948
+ //var sjs = pool.get_resource('Site JavaScript');
949
+ //console.log('sjs ' + sjs);
950
+
951
+ //throw 'stop';
952
+
953
+ // determine the name of the file to serve, serve that file
954
+ // Could use some more general kind of file server.
955
+
956
+ // We may want to serve from disk.
957
+ // I think this could work differently to an interface to the disk resource.
958
+ // The image resource, like some others, could directly access the disk.
959
+ // They may have their own bit of caching.
960
+
961
+
962
+ //console.log('splitPath', splitPath);
963
+
964
+ if (splitPath.length > 1) {
965
+ // At this point, can look for the file on disk within the app directory.
966
+ //console.log('rurl', rurl);
967
+ //console.log('req.url', req.url);
968
+ // replace /images/ with /img/
969
+ var project_disk_path = req.url.replace('images/', 'img/');
970
+ if (project_disk_path.substr(0, 1) == '/') project_disk_path = project_disk_path.substr(1);
971
+
972
+ // try to load it from disk.
973
+ // try to load it as a buffer
974
+ fs2.load_file_as_buffer(project_disk_path, function (err, buffer) {
975
+ if (err) {
976
+ console.log('error loading ' + project_disk_path + ': ' + err);
977
+
978
+
979
+ // Then try serving the file using the other methods, but will need to take care not to expect some resources to be there,
980
+ // such as the web_data resource.
981
+ // Want top have a very versitile web_data resource that uses a DB, but also to have the means to interact with the files on disk
982
+ // in the project directory.
983
+
984
+ res.writeHead(404, {
985
+ "Content-Type": "text/plain"
986
+ });
987
+ res.write("404 Not Found\n");
988
+ res.end();
989
+
990
+ //throw 'stop';
991
+
992
+
993
+ const old_fn = () => {
994
+ if (splitPath.length == 2) {
995
+
996
+
997
+ // Could check options to see if to look in the database, or the file system.
998
+ // Perhaps could have a website document storage abstraction that will store in the file system or the
999
+ // database.
1000
+ var fileName = splitPath[1];
1001
+
1002
+ // See if we can get the document with the key of the filename of the image.
1003
+ // Perhaps it will be stored as a site image.
1004
+
1005
+ that.get_document(fileName, function (err, res_get_document) {
1006
+ if (err) {
1007
+ throw err;
1008
+ } else {
1009
+ //console.log('res_get_document', res_get_document);
1010
+ console.log('cb get document');
1011
+
1012
+ // Now we have it,
1013
+
1014
+ var doc_keys = Object.keys(res_get_document);
1015
+ console.log('doc_keys', doc_keys);
1016
+
1017
+ // Need to know more information, such as the type_name
1018
+ // that extra info should probably get returned from the database.
1019
+ }
1020
+ });
1021
+
1022
+ /*
1023
+ //console.log('url_parts.path ' + url_parts.path);
1024
+ var filePath = url_parts.path.substr(1);
1025
+ //console.log('module.uri ' + module.uri);
1026
+ var val2 = path.dirname(module.uri);
1027
+ console.log('val2 ' + val2);
1028
+ //throw '9) stop';
1029
+ //var diskPath = val2 + '/../../images/' + fileName;
1030
+ var diskPath = '../../ws/img/' + fileName;
1031
+ // Also making use of custom paths...
1032
+ // First check if such an image is in a specifically served directory.
1033
+ var served_directories = this.meta.get('served_directories');
1034
+ //console.log('served_directories ' + stringify(served_directories));
1035
+ // see if the file exists in any of the served directories
1036
+ // search for the file in the served directories.
1037
+ // will be an asyncronous search, and use an array of function calls with call_multi.
1038
+ var fns = [];
1039
+ var found_path;
1040
+ each(served_directories, function(served_directory) {
1041
+ //console.log('served_directory', served_directory);
1042
+ var dir_val = served_directory.value();
1043
+ //console.log('dir_val', dir_val);
1044
+ var dir_name = dir_val.name;
1045
+ //console.log('dir_name', dir_name);
1046
+ var search_path = dir_name + '/' + fileName;
1047
+ //console.log('search_path', search_path);
1048
+ fns.push(function(callback) {
1049
+ // check that directory
1050
+ fs.exists(search_path, function(exists) {
1051
+ //console.log('exists', exists);
1052
+ if (!found_path && exists) {
1053
+ found_path = search_path;
1054
+ }
1055
+ callback(null, exists);
1056
+ })
1057
+ })
1058
+ });
1059
+ call_multi(fns, function(err, res2) {
1060
+ if (err) {
1061
+ throw err;
1062
+ } else {
1063
+ //console.log('found_path', found_path);
1064
+ if (found_path) {
1065
+ diskPath = found_path;
1066
+ serve_image_file_from_disk(diskPath, res);
1067
+ }
1068
+ }
1069
+ });
1070
+ //throw 'stop';
1071
+ */
1072
+
1073
+ /*
1074
+ fs2.load_file_as_string(diskPath, function (err, data) {
1075
+ if (err) {
1076
+ throw err;
1077
+ } else {
1078
+ //var servableJs = updateReferencesForServing(data);
1079
+ res.writeHead(200, {'Content-Type': 'text/css'});
1080
+ res.end(data);
1081
+ }
1082
+ });
1083
+ */
1084
+ } else {
1085
+ if (splitPath.length > 2) {
1086
+ // need to put the rest of it together...
1087
+ var fileName = splitPath.slice(1, splitPath.length).join('/');
1088
+ console.log('fileName', fileName);
1089
+ var filePath = url_parts.path.substr(1);
1090
+ //console.log('module.uri ' + module.uri);
1091
+ var val2 = path.dirname(module.uri);
1092
+ console.log('val2 ' + val2);
1093
+ //throw '9) stop';
1094
+ //var diskPath = val2 + '/../../images/' + fileName;
1095
+ var diskPath = '../../ws/img/' + fileName;
1096
+ // Do the search in the various served directories for the file.
1097
+
1098
+ var served_directories = this.served_directories;
1099
+ //console.log('served_directories ' + stringify(served_directories));
1100
+ // see if the file exists in any of the served directories
1101
+ // search for the file in the served directories.
1102
+ // will be an asyncronous search, and use an array of function calls with call_multi.
1103
+
1104
+ var fns = [];
1105
+ var found_path;
1106
+ each(served_directories, function (served_directory) {
1107
+ //console.log('served_directory', served_directory);
1108
+ var dir_val = served_directory.value();
1109
+ //console.log('dir_val', dir_val);
1110
+ var dir_name = dir_val.name;
1111
+ //console.log('dir_name', dir_name);
1112
+
1113
+ var search_path = dir_name + '/' + fileName;
1114
+ //console.log('search_path', search_path);
1115
+ fns.push(function (callback) {
1116
+ // check that directory
1117
+
1118
+ fs.exists(search_path, function (exists) {
1119
+ //console.log('exists', exists);
1120
+
1121
+ if (!found_path && exists) {
1122
+ found_path = search_path;
1123
+ }
1124
+ callback(null, exists);
1125
+ })
1126
+ })
1127
+ });
1128
+
1129
+ call_multi(fns, function (err, res2) {
1130
+ if (err) {
1131
+ throw err;
1132
+ } else {
1133
+ console.log('found_path', found_path);
1134
+ if (found_path) {
1135
+ diskPath = found_path;
1136
+ //serve_image_file_from_disk(diskPath, res);
1137
+ }
1138
+ serve_image_file_from_disk(diskPath, res);
1139
+ }
1140
+ });
1141
+ // /js/core/jsgui-lang-enh
1142
+ //console.log('!*!*!*! url_parts.path ' + url_parts.path);
1143
+ /*
1144
+ if (splitPath[1] == 'core') {
1145
+ var fileName = splitPath[2];
1146
+ var val2 = path.dirname(module.uri);
1147
+ //console.log('val2 ' + val2);
1148
+ var diskPath = val2 + '/../core/' + fileName;
1149
+ fs2.load_file_as_string(diskPath, function (err, data) {
1150
+ if (err) {
1151
+ throw err;
1152
+ } else {
1153
+ //var servableJs = updateReferencesForServing(data);
1154
+ res.writeHead(200, {'Content-Type': 'text/css'});
1155
+ res.end(data);
1156
+ }
1157
+ });
1158
+ }
1159
+ */
1160
+ }
1161
+ }
1162
+ }
1163
+ } else {
1164
+ console.log('loaded file, need to serve it');
1165
+ // need to set the mime type correctly.
1166
+ // We can get this from the file name for the moment.
1167
+ // serve_image_file_from_buffer
1168
+ //serve_image_file_from_disk(diskPath, res);
1169
+ console.log('buffer', buffer);
1170
+ console.log('project_disk_path', project_disk_path);
1171
+ serve_image_file_from_buffer(buffer, project_disk_path, res);
1172
+ }
1173
+ })
1174
+ }
1175
+ }
1176
+ }
1177
+ }
1178
+ }
1179
+ }
1180
+
1181
+
1182
+ //return Site_Images;
1183
+
1184
+
1185
+ //});
1186
1186
  module.exports = Site_Images;