Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
cae3caac
提交
cae3caac
authored
10月 14, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit
上级
ca3aa1e9
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
122 行增加
和
3 行删除
+122
-3
pom.xml
pom.xml
+7
-0
Controller.java
.../java/com/example/afrishop_v3/controllers/Controller.java
+21
-1
ImageSearchController.java
...xample/afrishop_v3/controllers/ImageSearchController.java
+80
-0
WebSecurityConfig.java
...a/com/example/afrishop_v3/security/WebSecurityConfig.java
+1
-1
Blue_Tshirt.jpg
src/main/resources/Blue_Tshirt.jpg
+0
-0
afrishop-6e142-a74ff3091e0c.json
src/main/resources/afrishop-6e142-a74ff3091e0c.json
+12
-0
application.properties
src/main/resources/application.properties
+1
-1
没有找到文件。
pom.xml
浏览文件 @
cae3caac
...
@@ -54,6 +54,13 @@
...
@@ -54,6 +54,13 @@
<artifactId>
unirest-java
</artifactId>
<artifactId>
unirest-java
</artifactId>
<version>
1.4.9
</version>
<version>
1.4.9
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-vision -->
<dependency>
<groupId>
com.google.cloud
</groupId>
<artifactId>
google-cloud-vision
</artifactId>
<version>
1.100.2
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hashids/hashids -->
<!-- https://mvnrepository.com/artifact/org.hashids/hashids -->
<dependency>
<dependency>
<groupId>
org.hashids
</groupId>
<groupId>
org.hashids
</groupId>
...
...
src/main/java/com/example/afrishop_v3/controllers/Controller.java
浏览文件 @
cae3caac
...
@@ -2,7 +2,12 @@ package com.example.afrishop_v3.controllers;
...
@@ -2,7 +2,12 @@ package com.example.afrishop_v3.controllers;
import
com.example.afrishop_v3.util.HttpClientUtil
;
import
com.example.afrishop_v3.util.HttpClientUtil
;
import
com.example.afrishop_v3.util.IdUtil
;
import
com.example.afrishop_v3.util.IdUtil
;
import
com.google.api.gax.paging.Page
;
import
com.google.auth.oauth2.GoogleCredentials
;
import
com.google.auth.oauth2.GoogleCredentials
;
import
com.google.cloud.storage.Bucket
;
import
com.google.cloud.storage.Storage
;
import
com.google.cloud.storage.StorageOptions
;
import
com.google.common.collect.Lists
;
import
com.google.firebase.FirebaseApp
;
import
com.google.firebase.FirebaseApp
;
import
com.google.firebase.FirebaseOptions
;
import
com.google.firebase.FirebaseOptions
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseAuth
;
...
@@ -22,7 +27,7 @@ import java.text.DecimalFormat;
...
@@ -22,7 +27,7 @@ import java.text.DecimalFormat;
import
java.text.NumberFormat
;
import
java.text.NumberFormat
;
import
java.util.HashMap
;
import
java.util.HashMap
;
class
Controller
{
abstract
class
Controller
{
String
uid
()
{
String
uid
()
{
return
IdUtil
.
createIdbyUUID
();
return
IdUtil
.
createIdbyUUID
();
...
@@ -32,6 +37,21 @@ class Controller {
...
@@ -32,6 +37,21 @@ class Controller {
static
int
id
=
0
;
static
int
id
=
0
;
NumberFormat
formatter
=
new
DecimalFormat
(
"#0.00"
);
NumberFormat
formatter
=
new
DecimalFormat
(
"#0.00"
);
void
authExplicit
()
throws
IOException
{
// You can specify a credential file by providing a path to GoogleCredentials.
// Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS environment variable.
InputStream
in
=
new
ClassPathResource
(
"afrishop-6e142-a74ff3091e0c.json"
).
getInputStream
();
GoogleCredentials
credentials
=
GoogleCredentials
.
fromStream
(
in
)
.
createScoped
(
Lists
.
newArrayList
(
"https://www.googleapis.com/auth/cloud-platform"
));
Storage
storage
=
StorageOptions
.
newBuilder
().
setCredentials
(
credentials
).
build
().
getService
();
System
.
out
.
println
(
"Buckets:"
);
Page
<
Bucket
>
buckets
=
storage
.
list
();
for
(
Bucket
bucket
:
buckets
.
iterateAll
())
{
System
.
out
.
println
(
bucket
.
toString
());
}
}
private
FirebaseApp
getApp
()
{
private
FirebaseApp
getApp
()
{
FirebaseOptions
options
;
FirebaseOptions
options
;
try
{
try
{
...
...
src/main/java/com/example/afrishop_v3/controllers/ImageSearchController.java
0 → 100644
浏览文件 @
cae3caac
package
com
.
example
.
afrishop_v3
.
controllers
;
import
com.example.afrishop_v3.base.Result
;
import
com.example.afrishop_v3.enums.ResultCodeEnum
;
import
com.google.api.client.util.IOUtils
;
import
com.google.cloud.vision.v1.*
;
import
com.google.cloud.vision.v1.Feature.Type
;
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.Descriptors
;
import
com.google.protobuf.GeneratedMessageV3
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"search/image"
)
public
class
ImageSearchController
extends
Controller
{
// Imports the Google Cloud client library
@GetMapping
public
Result
main
()
throws
Exception
{
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
Result
errorDecoding
=
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Error decoding"
);
authExplicit
();
try
(
ImageAnnotatorClient
vision
=
ImageAnnotatorClient
.
create
())
{
// The path to the image file to annotate
String
fileName
=
"./resources/wakeupcat.jpg"
;
// Reads the image file into memory
//Path path = Paths.get(fileName);
InputStream
in
=
new
ClassPathResource
(
"Blue_Tshirt.jpg"
).
getInputStream
();
byte
[]
data
=
IOUtils
.
serialize
(
in
);
//byte[] data = Files.readAllBytes(path);
ByteString
imgBytes
=
ByteString
.
copyFrom
(
data
);
// Builds the image annotation request
List
<
AnnotateImageRequest
>
requests
=
new
ArrayList
<>();
Image
img
=
Image
.
newBuilder
().
setContent
(
imgBytes
).
build
();
Feature
feat
=
Feature
.
newBuilder
().
setType
(
Type
.
OBJECT_LOCALIZATION
).
build
();
AnnotateImageRequest
request
=
AnnotateImageRequest
.
newBuilder
().
addFeatures
(
feat
).
setImage
(
img
).
build
();
requests
.
add
(
request
);
// Performs label detection on the image file
BatchAnnotateImagesResponse
response
=
vision
.
batchAnnotateImages
(
requests
);
List
<
AnnotateImageResponse
>
responses
=
response
.
getResponsesList
();
for
(
AnnotateImageResponse
res
:
responses
)
{
if
(
res
.
hasError
())
{
System
.
out
.
format
(
"Error: %s%n"
,
res
.
getError
().
getMessage
());
return
errorDecoding
;
}
List
<
Map
<
Descriptors
.
FieldDescriptor
,
Object
>>
collect
=
res
.
getLocalizedObjectAnnotationsList
().
stream
().
map
(
GeneratedMessageV3:
:
getAllFields
).
collect
(
Collectors
.
toList
());
// for (LocalizedObjectAnnotation annotation : res.getLocalizedObjectAnnotationsList()) {
// annotation
// .getAllFields()
// .forEach((k, v) -> System.out.format("%s : %s%n", k., v.toString()));
// }
return
new
Result
<>(
collect
);
}
}
return
errorDecoding
;
}
}
src/main/java/com/example/afrishop_v3/security/WebSecurityConfig.java
浏览文件 @
cae3caac
...
@@ -58,7 +58,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -58,7 +58,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http
.
cors
().
and
().
csrf
().
disable
()
http
.
cors
().
and
().
csrf
().
disable
()
.
exceptionHandling
().
authenticationEntryPoint
(
unauthorizedHandler
).
and
()
.
exceptionHandling
().
authenticationEntryPoint
(
unauthorizedHandler
).
and
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
.
authorizeRequests
().
antMatchers
(
"/api/auth/**"
,
"/itemStation/**"
,
"/startPage/**"
,
"/goodsType/**"
,
"/home/**"
,
"/spider/**"
,
"/store/**"
,
"/shopify/**"
,
"/community/**"
,
"/version/**"
).
permitAll
()
.
authorizeRequests
().
antMatchers
(
"/api/auth/**"
,
"/search/image/**"
,
"/itemStation/**"
,
"/startPage/**"
,
"/goodsType/**"
,
"/home/**"
,
"/spider/**"
,
"/store/**"
,
"/shopify/**"
,
"/community/**"
,
"/version/**"
).
permitAll
()
.
antMatchers
(
"/api/test/**"
).
permitAll
()
.
antMatchers
(
"/api/test/**"
).
permitAll
()
.
anyRequest
().
authenticated
();
.
anyRequest
().
authenticated
();
...
...
src/main/resources/Blue_Tshirt.jpg
0 → 100644
浏览文件 @
cae3caac
52.6 KB
src/main/resources/afrishop-6e142-a74ff3091e0c.json
0 → 100644
浏览文件 @
cae3caac
{
"type"
:
"service_account"
,
"project_id"
:
"afrishop-6e142"
,
"private_key_id"
:
"a74ff3091e0cea23f89120f483ae313694a2c69e"
,
"private_key"
:
"-----BEGIN PRIVATE KEY-----
\n
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCou2lJZ78yw0LS
\n
jJvu3Qu1frgP5WJ2w+I6ornJ8Dasf5NeNPoeOUAmT3eZwInuGAwknd9hFwAci9FP
\n
M6WO4XX/6ckOyzTb0yDbUcpimpiJy0DP8HRBsVxVDonvUGqdRG2c/VYapxoW63y7
\n
Ns/utM31W+MIUgFw6Tw5RGqFh4x4FBk5nEWbUYNGPyqFNzlPjhkYOpwRi3r6h46p
\n
BPj77V+JyHjZFjM0X24bNxUP6FHDP4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7vcg07O0SVm08lLXy0S9AQmkwP3meqTTb4dTC9y/L7cFM1Jq16oOo1aDlDmCwcgm
\n
N0GQH6+oOMzVY3E2PUHKHHPFymNqYx0OpS23bpLH8DTH7JlHPucqqLzB26uQo2QR
\n
AbTSr9wSaq77v0gPixo0k0ZvmJpNPTQEcBMw9k+bAoGBAISbbAAsfcS04JjorSrh
\n
USMMjcSSOvo2sKzZNkLNUNcBhZhsjFyE1OcX0Sne/nlRwXo6JiusGSC6nKuWNYSf
\n
t1TTMlD0upjfR4xBDn8xsoVijt251tFRqegPBSaPD4wfv/rGLBoOfEmrZQstRaaq
\n
pzr0ho3T9W8GosN24WAHhLIX
\n
-----END PRIVATE KEY-----
\n
"
,
"client_email"
:
"firebase-adminsdk-ypj91@afrishop-6e142.iam.gserviceaccount.com"
,
"client_id"
:
"110654393006448219899"
,
"auth_uri"
:
"https://accounts.google.com/o/oauth2/auth"
,
"token_uri"
:
"https://oauth2.googleapis.com/token"
,
"auth_provider_x509_cert_url"
:
"https://www.googleapis.com/oauth2/v1/certs"
,
"client_x509_cert_url"
:
"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-ypj91%40afrishop-6e142.iam.gserviceaccount.com"
}
src/main/resources/application.properties
浏览文件 @
cae3caac
server.servlet.context-path
=
/zion
server.servlet.context-path
=
/zion
spring.jpa.hibernate.ddl-auto
=
update
spring.jpa.hibernate.ddl-auto
=
update
server.port
=
7000
server.port
=
7000
spring.datasource.url
=
jdbc:mysql://${MYSQL_HOST:
localhost
}:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.url
=
jdbc:mysql://${MYSQL_HOST:
165.22.82.105
}:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username
=
root
spring.datasource.username
=
root
spring.datasource.password
=
clement123
spring.datasource.password
=
clement123
spring.jpa.database-platform
=
org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database-platform
=
org.hibernate.dialect.MySQL5InnoDBDialect
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论