BinaryAssets & Fixes
+ Added binary assets + Added font Source Code Pro for the web logging viewer + Removed unreachable code at package static files
This commit is contained in:
		
							parent
							
								
									8f43171edf
								
							
						
					
					
						commit
						f0c73c3fd5
					
				
							
								
								
									
										14
									
								
								BinaryAssets/Access.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								BinaryAssets/Access.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | package BinaryAssets | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"github.com/SommerEngineering/Ocean/BinaryAssets/SourceCodePro" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func GetData(filename string) (data []byte) { | ||||||
|  | 	if obj, err := SourceCodePro.Asset(filename); err != nil { | ||||||
|  | 		return | ||||||
|  | 	} else { | ||||||
|  | 		data = obj | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										51
									
								
								BinaryAssets/Handlers.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								BinaryAssets/Handlers.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | package BinaryAssets | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"github.com/SommerEngineering/Ocean/Log" | ||||||
|  | 	LM "github.com/SommerEngineering/Ocean/Log/Meta" | ||||||
|  | 	"github.com/SommerEngineering/Ocean/MimeTypes" | ||||||
|  | 	"github.com/SommerEngineering/Ocean/Shutdown" | ||||||
|  | 	"net/http" | ||||||
|  | 	"strings" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func HandlerBinaryAssets(response http.ResponseWriter, request *http.Request) { | ||||||
|  | 
 | ||||||
|  | 	if Shutdown.IsDown() { | ||||||
|  | 		http.NotFound(response, request) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// Prepare the path:
 | ||||||
|  | 	path := strings.Replace(request.RequestURI, `/binaryAssets/`, ``, 1) | ||||||
|  | 	path = strings.Replace(path, `%20`, ` `, -1) | ||||||
|  | 	fileType := `` | ||||||
|  | 
 | ||||||
|  | 	// Determine the MIME type:
 | ||||||
|  | 	if mimeType, errMime := MimeTypes.DetectType(path); errMime != nil { | ||||||
|  | 		Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityMiddle, LM.ImpactMiddle, LM.MessageNameNOTFOUND, `Was not able to detect the MIME type of the font.`, errMime.Error(), path) | ||||||
|  | 		http.NotFound(response, request) | ||||||
|  | 		return | ||||||
|  | 	} else { | ||||||
|  | 		fileType = mimeType.MimeType | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if fileType == `` { | ||||||
|  | 		Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelSECURITY, LM.SeverityCritical, LM.ImpactUnknown, LM.MessageNameNOTFOUND, `The mime type is unknown.`, path) | ||||||
|  | 		http.NotFound(response, request) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	contentData := GetData(path) | ||||||
|  | 	if contentData == nil { | ||||||
|  | 		Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameDATABASE, `The desired file was not found.`, path) | ||||||
|  | 		http.NotFound(response, request) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	fileLenText := fmt.Sprintf(`%d`, len(contentData)) | ||||||
|  | 	response.Header().Add(`Content-Length`, fileLenText) | ||||||
|  | 	response.Header().Add(`Content-Type`, fileType) | ||||||
|  | 	response.Write(contentData) | ||||||
|  | } | ||||||
							
								
								
									
										270
									
								
								BinaryAssets/SourceCodePro/SourceCodePro.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										270
									
								
								BinaryAssets/SourceCodePro/SourceCodePro.go
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										9
									
								
								BinaryAssets/Variables.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								BinaryAssets/Variables.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | package BinaryAssets | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	LM "github.com/SommerEngineering/Ocean/Log/Meta" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | var ( | ||||||
|  | 	senderName LM.Sender = `System::BinaryAssets` | ||||||
|  | ) | ||||||
| @ -52,8 +52,4 @@ func HandlerStaticFiles(response http.ResponseWriter, request *http.Request) { | |||||||
| 		Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameBROWSER, `A static file was requested.`, path) | 		Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameBROWSER, `A static file was requested.`, path) | ||||||
| 	} | 	} | ||||||
| 	return | 	return | ||||||
| 
 |  | ||||||
| 	http.NotFound(response, request) |  | ||||||
| 	Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameNOTFOUND, `The desired file is not part of the ZIP file.`, `Do you use an old version?`, path) |  | ||||||
| 	return |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package System | package System | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/SommerEngineering/Ocean/BinaryAssets" | ||||||
| 	"github.com/SommerEngineering/Ocean/ConfigurationDB" | 	"github.com/SommerEngineering/Ocean/ConfigurationDB" | ||||||
| 	"github.com/SommerEngineering/Ocean/Handlers" | 	"github.com/SommerEngineering/Ocean/Handlers" | ||||||
| 	"github.com/SommerEngineering/Ocean/ICCC" | 	"github.com/SommerEngineering/Ocean/ICCC" | ||||||
| @ -29,6 +30,7 @@ func InitHandlers() { | |||||||
| 	Handlers.AddAdminHandler(`/staticFiles/`, StaticFiles.HandlerStaticFiles) | 	Handlers.AddAdminHandler(`/staticFiles/`, StaticFiles.HandlerStaticFiles) | ||||||
| 	Handlers.AddAdminHandler(`/next/number`, NumGen.HandlerGetNext) | 	Handlers.AddAdminHandler(`/next/number`, NumGen.HandlerGetNext) | ||||||
| 	Handlers.AddAdminHandler(`/ICCC`, ICCC.ICCCHandler) | 	Handlers.AddAdminHandler(`/ICCC`, ICCC.ICCCHandler) | ||||||
|  | 	Handlers.AddAdminHandler(`/binaryAssets/`, BinaryAssets.HandlerBinaryAssets) | ||||||
| 
 | 
 | ||||||
| 	if ConfigurationDB.Read(`MapStaticFiles2Root`) == "true" { | 	if ConfigurationDB.Read(`MapStaticFiles2Root`) == "true" { | ||||||
| 		Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `The static files are mapped to the root.`) | 		Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `The static files are mapped to the root.`) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user